> 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:
Go to disassembly:
1. Before the stack frame allocation of the main function:
__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
3. The calling process of the Add function
Assembly code:
Stack frame creation process:
4. The function ends the process:
The created temporary space is destroyed when popped.