Here's a small snippet I found from draw.asm:
add r9 , [copyxe]
add r9 , [copyxe]
add r9 , [copyxe]
sub r9 , [copyx]
sub r9 , [copyx]
sub r9 , [copyx]
add r10 , [sizex]
add r10 , [sizex]
add r10 , [sizex]
add r14 , 1
72 bytes.Here's what GCC generates with -Os for the same code:
imul rax,qword ptr [copyxe],3
inc r14
add r9,rax
imul rax,qword ptr [sizex],3
add r10,rax
imul rax,qword ptr [copyx],-3
add r9,rax
36 bytes.As a bonus, GCC with -O2:
mov rax,[copyxe]
add r14,1
lea rax,[rax+rax*2]
add r9,rax
mov rax,[sizex]
lea rax,[rax+rax*2]
add r10,rax
mov rax,[copyx]
mov rcx,rax
neg rcx
lea rax,[rax+rcx*4] ; clever!
add r9,rax
52 bytes.So, not only does GCC hugely beat this snippet of handwritten Menuet assembly in code size, it can even do so handily while folding all the repeated additions into LEA and eliminating most of the loads.
This is an excellent example of why you shouldn't write in assembler.