How does a function in memory go through a series of process calls? Pointer Register ESP,EBP
1. First figure out the two very important pointer register ESP,EBP in the function call. Some understanding of these two registers:
The ESP is a stack pointer, which is used to point to the stack top
EBP is the frame pointer, which points to the stack bottom of the stack. function Stack Frame
2. The function calls the process needs to open up the space, uses in this function's call the temporary variable preservation, the field protection. This stack space is what we call a function stack frame.
The stack space is used by high addresses to low addresses. Function call procedure
When the function is called, do the following:
1. Press the frame pointer into the stack: push EBP
2. Save current stack pointer with EBP: MOV ebp, esp
3. Stack pointer decrement, the resulting memory is used to store the local state of the called function: Sub ESP, 4Ch
4. When the function is called, the first stack is the address of the next instruction after the called function (the next executable statement of the function call statement, the address of the next instruction in the calling instruction), and then the parameters of the function, in most C compilers, the argument is the right to the left into the stack, the first pressure parameter B in the pressure parameter a , and then a local variable in the function. Note that static variables are not in the stack.
5. When the function call is complete, the local variable is first out of the stack, then the parameter, and the last stack pointer points to the first saved address, which is the next instruction in the main function, and the program continues to run from that point.
C Language-call procedure for functions, creation and destruction of stack frames.