Changes in the function call stack

I remember that before I wrote this, but can not find it. . .

Such is assumed that the current stack (from top to bottom, from high to low addresses address)

ebp

...

esp

Then call func a, ab pass two parameters

Then the process is

 

1 2 b push the PUSH parameter, ESP. 4-
the PUSH Parameter 2 1 a push, esp-4 (right to left)
the CALL A call (in this case push eip (return address), so that if a call parameter to be caller ebp + 8, the two parameters have to +12)

 

A:
PUSH EBP save ebp (ebp caller, the time for recovery caller stack)
MOV EBP, ESP alter the stack frame after the access parameters through ebp, esp access the local variables (the original function of the stack becomes esp the stack base address of the new function EBP)
the SUB the ESP, allocation of local variable space. 8 (top of the stack and then down the original function, the function of local variables allocated to a new space)

...
the ADD the ESP,. 8 (ESP restored to the original top of the stack)
the POP EBP EBP restored (restored to the original EBP)
the RETN return. 8, esp + 8 (return to the original position of the above parameters to perform position)

 

 

Guess you like

Origin www.cnblogs.com/lqerio/p/12101720.html