组件x86-“离开"组件操作说明 [英] Assembly x86 - "leave" Instruction

查看:80
本文介绍了组件x86-“离开"组件操作说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据说"leave"指令类似于:

It's said that the "leave" instruction is similar to:

movl %ebp, %esp
popl %ebp

我了解movl %ebp, %esp部分,它的作用是释放存储的内存(如

I understand the movl %ebp, %esp part, and that it acts to release stored up memory (as discussed in this question).

但是popl %ebp代码的目的是什么?

But what is the purpose of the popl %ebp code?

推荐答案

LEAVEENTER的副本. ENTER指令通过首先将EBP推入堆栈,然后将ESP复制到EBP来建立堆栈帧,因此LEAVE必须执行相反的操作,即将EBP复制到ESP并然后从堆栈中恢复旧的EBP.

LEAVE is the counterpart to ENTER. The ENTER instruction sets up a stack frame by first pushing EBP onto the stack and then copies ESP into EBP, so LEAVE has to do the opposite, i.e. copy EBP to ESP and then restore the old EBP from the stack.

请参见

See the section named PROCEDURE CALLS FOR BLOCK-STRUCTURED LANGUAGES in Intel's Software Developer's Manual Vol 1 if you want to read more about how ENTER and LEAVE work.

enter n,0完全等同于(并应替换为)

enter n,0 is exactly equivalent to (and should be replaced with)

push  %ebp
mov   %esp, %ebp     # ebp = esp,  mov  ebp,esp in Intel syntax
sub   $n, %esp       # allocate space on the stack.  Omit if n=0

leave完全等同于

leave is exactly equivalent to

mov   %ebp, %esp     # esp = ebp,  mov  esp,ebp in Intel syntax
pop   %ebp

enter非常慢,编译器不使用它,但是leave很好. ( http://agner.org/optimize ).如果编译器完全构成堆栈框架,则它们会使用leave(至少gcc会这样做).但是,如果esp已经等于ebp,则仅pop ebp效率最高.

enter is very slow and compilers don't use it, but leave is fine. (http://agner.org/optimize). Compilers do use leave if they make a stack frame at all (at least gcc does). But if esp is already equal to ebp, it's most efficient to just pop ebp.

这篇关于组件x86-“离开"组件操作说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆