I'm pretty comfortable with "C", but where I lack, is understanding what types of options must be passed to compiler to produce the tightest code possible. Here is an example of a formula in "C";
int ADDR = VIDEO_BASE + (WND_X + POS_X) + ((WND_Y + POS_Y) * SCR_X) * 2 and the resulting assember code
Calc_ADDR:
push rcx
xor eax, eax
; Determine vertical offset in characters.
mov al, [rbx + WND_Y] ; Get windows vertical offset from top left
add al, [rbx + POS_Y]
sub al, 2 ; Zero index co-ordinates
mul byte [rbx + SCR_X] ; Number of columns / row
; Determine horizonal offset in characters.
mov rcx, rax
xor eax, eax
mov al, [rbx + WND_X]
add al, [rbx + POS_X]
sub al, 2 ; Zero index co-ordinates
; Result double as each position has character and associated attribute.
add eax, ecx
shl rax, 1 ; Offset *= 2
add rax, [rbx + VIDEO_BASE]
pop rcx
ret
and resultant code looks like this
00 51 push rcx
01 31C0 xor eax,eax
03 8A430D mov al,[rbx+0xd]
06 024303 add al,[rbx+0x3]
09 2C02 sub al,0x2
0B F623 mul byte [rbx]
0D 4889C1 mov rcx,rax
10 31C0 xor eax,eax
12 8A430C mov al,[rbx+0xc]
15 024302 add al,[rbx+0x2]
18 2C02 sub al,0x2
1A 01C8 add eax,ecx
1C 48D1E0 shl rax,1
1F 48034304 add rax,[rbx+0x4]
23 59 pop rcx
24 C3 ret
GCC is probably what I'm going to use or at least its variant for windows. Unless there is another option for windows other than visual studio. It would be nice to see the disassembled code that corresponds to your response.
Thanks.