ret指令会将4添加到esp寄存器吗?

12
3个回答

25

是的,它执行。

pop eip
你可以使用 标签来呈现代码。
mov eax, [esp]
jmp eax

为了避免这种情况。

编辑:这就是ret的作用。例如,jmp rel_offet实际上就是一个隐藏的add eip,offset,或者jmp absolute_offset实际上就是mov eip,absolute_offset。当然,处理器处理它们的方式有所不同,但从程序员的角度来看,这就是发生的所有事情。

此外,还有一种特殊形式的retret imm8,它还将这个imm8值添加到esp中:例如__stdcall函数使用它来从堆栈中丢弃其参数。更不用说在16位模式下使用的retf版本,它还从堆栈中弹出cs

编辑2:

pop register

意思是:

mov register, [esp]
add esp, 4

EIP 不能直接被修改吗? - remainn
如果只有指令: ret 它会改变寄存器ESP的值吗? - remainn
1
@remainnjmp target_of_jump 是直接修改 eip 的方法(因为 mov eip, target_of_jump 不起作用)。有关 Intel 64 和 IA32 汇编的详细信息,我建议阅读 "Intel® 64 and IA-32 Architectures Software Developer's Manual":http://www.intel.com/products/processor/manuals/顺便说一句:除非我在 ARM 处理器上弄错了,否则你可以直接读写程序计数器(它在那里是寄存器 15)。 - Nubok

2

yes, because on the stack there is (well, there should be, see buffer overflow) the address to where resume the execution of the program. So ret means

pop ret_addr           ; pop deletes ret_addr from stack by adding 4 to esp
mov eip, ret_addr

这是

pop eip

正如 ruslik 所说

0

是的,当处理器运行在32位保护模式下时。在实模式或16位保护模式下,RET会执行POP IP指令,这将导致ADD ESP,2(而不是4)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接