RET,RETN,RETF - 如何使用它们 [英] ret, retn, retf - how to use them

查看:374
本文介绍了RET,RETN,RETF - 如何使用它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下ASM code:

I have the following asm code:

; int __stdcall wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
_wWinMain@16 proc near

var_8= dword ptr -8
var_4= dword ptr -4
hInstance= dword ptr  8
hPrevInstance= dword ptr  0Ch
lpCmdLine= dword ptr  10h
nShowCmd= dword ptr  14h

push    ebp
mov     ebp, esp
sub     esp, 8
mov     [ebp+var_4], 5
mov     eax, [ebp+var_4]
add     eax, 1
mov     [ebp+var_8], eax
xor     eax, eax
mov     esp, ebp
pop     ebp
retn    10h

从我读,你有3种类型的返回指令:RET,RETN和RETF,意味着回报,回报附近并返回为止。它们允许一个可选的参数为nbytes,我想这是字节数流行,从定义的变量。什么时候应该使用RETN或RETF代替RET?我如何计算可选参数,参数nBytes?

From what I read, you have 3 types of return instruction: ret, retn and retf, meaning return, return near and return far. They allow an optional argument nBytes, that I guess it's the number of bytes to pop, from the defined variables. When should I use retn or retf instead of ret? How can I calculate the optional parameter, nBytes?

推荐答案

在助记符RET N,N是在栈上参数的大小。在这种情况下,它是4×4 = 16(10H)为四个DWORD。结果
但是,这仅适用于调用约定时,被叫方负责栈清除。在cdecl调用约定的情况下,RET应该是没有任何数字,因为调用方负责清理堆栈

In the mnemonic ret N, N is the size of parameters on the stack. In this case it is 4 * 4 = 16 (10h) for 4 DWORDs.
But this only applies to calling conventions when the callee is responsible for stack cleanup. In case of cdecl convention the ret should be without any numbers, as the caller is responsible for stack cleanup.

这篇关于RET,RETN,RETF - 如何使用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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