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.