[英]How does this asm for a stdcall function clean args from the stack?
I have simple code.我有简单的代码。 StdCall
is __stdcall
and CdeclCall
is __cdecl
. StdCall
是__stdcall
并且CdeclCall
是__cdecl
。
#include <stdio.h>
int __stdcall StdCall(int a,int b)
{
return a + b;
}
int __cdecl CdeclCall(int a,int b)
{
return a + b;
}
int main(int argc, char **argv) {
StdCall(10,20);
CdeclCall(10,20);
printf("Done");
return 0;
}
Part of Disassabmbly of main() for StdCall (Main does not clear stack for StdCall)用于 StdCall 的 main() Disassabmbly 的一部分(Main不清除 StdCall 的堆栈)
push 20 ; 00000014H
push 10 ; 0000000aH
call ?StdCall@@YGHHH@Z ; StdCall
Part of Disassabmbly of main() for CdeclCall (Main does clear stack for CdeclCall)主要Disassabmbly()为CdeclCall的部分(主要做明确的堆栈CdeclCall)
push 20 ; 00000014H
push 10 ; 0000000aH
call ?CdeclCall@@YAHHH@Z ; CdeclCall
add esp, 8 ; Stack cleared here
Now, it is responsibility of StdCall to remove its args from the stack, but disassembly does not show any code which pops the ags to clear / clean the stack.现在,StdCall 负责从堆栈中删除其 args,但反汇编不会显示任何弹出 ag 以清除/清理堆栈的代码。
Disassembly for StdCall StdCall 的反汇编
push ebp
mov ebp, esp
sub esp, 192 ; 000000c0H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-192]
mov ecx, 48 ; 00000030H
mov eax, -858993460 ; ccccccccH
rep stosd
mov eax, DWORD PTR _a$[ebp]
add eax, DWORD PTR _b$[ebp]
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 8
Is it runtime activity to generate clearing stack code for __stdcall
or I have taken concept wrongly?为__stdcall
生成清除堆栈代码是运行时活动还是我错误地__stdcall
了概念?
It's part of the ret 8
instruction - 8 is the number of bytes to add to the stack pointer after popping the return address.它是ret 8
指令的一部分 - 8 是弹出返回地址后添加到堆栈指针的字节数。
https://www.felixcloutier.com/x86/ret https://www.felixcloutier.com/x86/ret
See also What is the meaning and usage of __stdcall?另请参阅__stdcall 的含义和用法是什么? for more about the @
decorations on C functions names in Windows.有关 Windows 中 C 函数名称上的@
装饰的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.