ret 指令是否将 4 添加到 esp 寄存器? [英] Does the ret instruction add 4 to esp register?

查看:97
本文介绍了ret 指令是否将 4 添加到 esp 寄存器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ret 指令 是否会导致esp"?注册要增加 4 个?

Does the ret instruction cause "esp" register to be increased by 4?

推荐答案

是的,它执行

pop eip

你可以使用

mov eax, [esp]
jmp eax

避免它.

这正是 ret 所做的.例如,jmp rel_offet 只不过是一个隐藏的 add eip, offset,或者 jmp absolute_offsetmov 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.

编辑 2:

pop register

意思是:

mov register, [esp]
add esp, 4

这篇关于ret 指令是否将 4 添加到 esp 寄存器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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