Why use ebp in c calling convention?

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
Peter H

Why use ebp in c calling convention?

Post 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?
carbonBased

RE:Why use ebp in c calling convention?

Post 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
Post Reply