Some extra ASM

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
azcoder
Posts: 3
Joined: Wed May 03, 2006 11:00 pm

Some extra ASM

Post by azcoder »

I am follwing a the little ASM tutorial on osdev.net:
http://www.osdev.net/howtos/1/index.html

But my gcc is giving me some extra asm.

test.c:
int main()
{
}

ndisasm -b 32 test.bin yields:
00000000 55 push ebp
00000001 89E5 mov ebp,esp
00000003 83EC08 sub esp,byte +0x8
00000006 83E4F0 and esp,byte -0x10
00000009 B800000000 mov eax,0x0
0000000E 29C4 sub esp,eax
00000010 C9 leave
00000011 C3 ret

Does anyone know why the extra stuff betwee mov ebp,esp and leave?

Thanks for any feedback.....
User avatar
Daedalus
Member
Member
Posts: 74
Joined: Sun Oct 16, 2005 11:00 pm
Location: Australia
Contact:

Re: Some extra ASM

Post by Daedalus »

I'm not sure, but I think that's just code to give you access to any parameters.
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Some extra ASM

Post by JAAman »

push ebp
mov ebp, esp
is sufficient to give access to parameters

sub esp, 0x08
not sure why this is -- it appears to be reserving some space on the stack, but im not sure why...

this is aligning the stack:

and esp, 0xFFFF FFF0 (-16 in two's complement, sign extended to 32bits)
this will adjust the stack to the nearest lower 16byte alignment (because it is always rounded down, there will never be any overwrite of a previous stack frame)



mov eax, 0
sub esp,eax

my guess is that this is to reserve space on the stack for local variables, since you dont have any local variables, it is using 0 (and not reserving any space at all)
Last edited by JAAman on Sun May 07, 2006 11:00 pm, edited 2 times in total.
Post Reply