Why use ebp in c calling convention?
Posted: Fri May 09, 2003 11:00 pm
I've read the "Mixing assembly and C" guide and I wonder why ebp is used.
The following code is from the guide:
_myfunc: push ebp
mov ebp,esp
sub esp,0x40 ; 64 bytes of local stack space
mov ebx,[ebp+8] ; first parameter to function
; some more code
leave ; mov esp,ebp / pop ebp
ret
So my questions are
1: Is ebp needed at all?, can't I just use esp
2: If ebp is not needed, why does it show up in all code examples?
I guess it is somewhat easier for an assembly programmer to use it, but why does DJGPP use it?
The following code is from the guide:
_myfunc: push ebp
mov ebp,esp
sub esp,0x40 ; 64 bytes of local stack space
mov ebx,[ebp+8] ; first parameter to function
; some more code
leave ; mov esp,ebp / pop ebp
ret
So my questions are
1: Is ebp needed at all?, can't I just use esp
2: If ebp is not needed, why does it show up in all code examples?
I guess it is somewhat easier for an assembly programmer to use it, but why does DJGPP use it?