Search code examples
assemblywindbgcallstackcalling-convention

Frame pointer, epb, and return address


The following image is from wikipedia entry on call stack and there is something that I don't understand completely:

alt text

I thought the frame pointer which is stored in ebp register is initialized as such in the prologue*:

push ebp  ; Preserve current frame pointer 
mov ebp, esp ; Create new frame pointer pointing to current stack top 
sub esp, 20 ; allocate 20 bytes worth of locals on stack. 

If so, then shouldn't the frame pointer in the image be pointing to after the return address and before it should be the previous frame pointer address and before that the return address? What am I missing?

Thanks!

*Taken from: What is exactly the base pointer and stack pointer? To what do they point?


Solution

  • Yes, you are right, frame pointer points to an address where is stored previous frame pointer, before return address. The correct picture would be

                   | locals
                   +---------
    frame pointer->| prev frame pointer
                   +--------
                   | return address
                   +--------