Search This Blog

Thursday, June 09, 2005

Silly MASM

So, I was just stepping through my new atomic functions code (the x86-32 version built with MASM) and noticed something kind of amusing. Take a look at the dissassembly (after it's been assembled):
00420A30 8B 54 24 04 mov edx,dword ptr [esp+4]
00420A34 8B 44 24 08 mov eax,dword ptr [esp+8]
00420A38 F0 87 02 lock xchg eax,dword ptr [edx]
00420A3B C2 08 00 ret 8
00420A3E 8B FF mov edi,edi
00420A40 8B 54 24 04 mov edx,dword ptr [esp+4]
00420A44 8B 44 24 08 mov eax,dword ptr [esp+8]
00420A48 F0 0F C1 02 lock xadd dword ptr [edx],eax
00420A4C C2 08 00 ret 8
00420A4F 90 nop
00420A50 8B 4C 24 04 mov ecx,dword ptr [esp+4]
00420A54 8B 44 24 0C mov eax,dword ptr [esp+0Ch]
00420A58 8B 54 24 08 mov edx,dword ptr [esp+8]
00420A5C F0 0F B1 11 lock cmpxchg dword ptr [ecx],edx
00420A60 C2 0C 00 ret 0Ch
00420A63 8D A4 24 00 00 00 00 lea esp,[esp]
00420A6A 8D 9B 00 00 00 00 lea ebx,[ebx]

See how it pads out the functions, to align new functions on paragraph (16 byte) boundaries? Well, that's exactly what I told it to do. But what's amusing is WHAT it pads the functions with. It seems to like to fill the gaps with do-nothing instructions that consume the fewest possible cycles. No idea what the point of this is, but I thought it was humorous.

No comments: