_function:
push ebp ;store the old base pointer
mov ebp, esp ;make the base pointer point to the current
;stack location – at the top of the stack is the
;old ebp, followed by the return address and then
;the parameters.
sub esp, x ;x is the size, in bytes, of all
;"automatic variables" in the function
at the top of the stack is the old ebp, followed by the return address and then the parameters.
The old ebp is there because push ebp
,
but why are the return address and the parameters there too?
UPDATE
Standard Exit Sequence
mov esp, ebp ;reset the stack to "clean" away the local variables
pop ebp ;restore the original base pointer
ret ;return from the function
What does ret
actually do?I think the esp should have already reached the return address at the line pop ebp