问题描述
"ret"指令是否导致"esp"寄存器加4?
Does "ret" instruction cause "esp" register added by 4?
推荐答案
是的,它执行
pop eip
您可以使用
mov eax, [esp]
jmp eax
避免它.
这正是ret
的作用.例如,jmp rel_offet
就是隐藏的add eip, offset
,或者jmp absolute_offset
是mov eip, absolute_offset
.当然,处理器处理它们的方式有所不同,但是从程序员的角度来看,这都是发生了.
It's exactly what ret
does. For example, jmp rel_offet
is nothing than a hidden add eip, offset
, or jmp absolute_offset
is mov eip, absolute_offset
. Sure there are differences in the way the processor treats them, but from programmer's point of view it's all that happens.
此外,还有一种特殊形式的ret
:ret imm8
还将此imm8值添加到esp
:例如,__stdcall
函数使用它来从堆栈中丢弃其参数.更不用说在16位模式下使用的retf
版本,该版本也会从堆栈中弹出cs
.
Also, there is a special form of ret
: ret imm8
that also adds this imm8 value to esp
: for example a __stdcall
function uses it to discard its parameters from the stack. Not to mention retf
version, used in 16bit mode, that also pops the cs
from the stack.
pop register
表示:
mov register, [esp]
add esp, 4
这篇关于ret指令会导致esp寄存器加4吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!