c++ - gcc编译后每个函数开始的 “push %ebp; movl %esp, %ebp” 是什么意思
天蓬老师
天蓬老师 2017-04-17 13:07:07
0
3
1212
push %ebp
movl %esp, %ebp

是什么意思?有什么作用?为什么要这样做???

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
迷茫

ebp is the frame pointer and esp is the stack pointer. These two lines of code save the old frame and create a new stack frame. Procedure calls in assembly require this action

Peter_Zhu

Create a stack frame, which can be optimized. Keeping this is mainly convenient for debugging, and you can trace the function call chain.
unsigned long *p=ebp;
*(p+1) is the return address of the calling function.
p=*p is the frame of the upper-level function
*(p+1) is the return address of the calling function of the upper-level function
You can always trace it back to the top function through this.

阿神

This is related to the function stack frame.
When a process starts, a stack frame will be created for the current process. The machine uses the stack to pass process parameters and store return information. %ebp is the frame pointer and %esp is the stack pointer. The two sentences you mentioned are stack building statements.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template