Page 1 of 1

Why use ebp in c calling convention?

Posted: Fri May 09, 2003 11:00 pm
by Peter H
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?

RE:Why use ebp in c calling convention?

Posted: Fri May 09, 2003 11:00 pm
by carbonBased
This is what ebp was designed for, and it simply makes things easier.

esp will change values throughout your proceedure, no doubt; any push or pop will effect all your locations, and make it difficult to code.

Jeff