stack frame - function call process

> What is a stack frame

> Detailed explanation of stack frame

1. What is a stack frame
Definition : A stack frame is also called a procedure activity record, which is a data structure used by the compiler to implement procedure/function calls.
Each function call is a process. This process needs to open up space and allocate addresses for the function, which is used to save and transfer temporary variables in this function call. We call this space the function stack frame.

2. Detailed explanation of stack frame

Take a simple code as an example:
write picture description here

Go to disassembly:

write picture description here

1. Before the stack frame allocation of the main function:
write picture description here

__tmainCRTStartup is called before calling the main function
edp stores the address pointing to the bottom of the function stack frame
esp stores the address pointing to the top of the function stack frame

2. The stack frame allocation of the main function
write picture description here

3. The calling process of the Add function
Assembly code:
write picture description here

Stack frame creation process:
write picture description here

4. The function ends the process:
write picture description here

The created temporary space is destroyed when popped.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324443787&siteId=291194637