Frame pointer, epb and return address

The following image from the wikipedia entry in the call stack is something that I do not fully understand:

alt text

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

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, should you not indicate the frame pointer on the image after the return address and before it is indicated by the previous address of the pointer on the frame and before this return address? What am I missing?

Thank!

* Adapted from: What is a pointer to a base pointer and a stack pointer? What are they pointing to?

+3
source share
2 answers

, , , , .

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

. , . , :

push ebp  ; Push the ebp; The ebp address will pushed on stack and sp will be decremented
mov ebp, esp ;  EBP will now point the same as ESP which is previous value of EBP
sub esp, 20 ;    ESP will be subtracted further to create frame for local variables

: EBP EBP. ESP 20 ESP. 20 .

0

Source: https://habr.com/ru/post/1779940/


All Articles