_cdecl,_stdcall,_fastcall 三种调用约定

头文件代码:

void _cdecl demo_cdecl(int, int, int){};
void _stdcall demo_stdcall(int, int, int){};
void _fastcall demo_fastcall(int, int, int){};
源文件代码:
#include "test.h"

void main()
{
	calling_convention();//调用3种约定
}
void calling_convention()
{
	demo_cdecl(1,2,3);
	demo_stdcall(1, 2, 3);
	demo_fastcall(1, 2, 3);
}
反汇编代码:
.text:004133C0 ; void __cdecl calling_convention()
.text:004133C0 ?calling_convention@@YAXXZ proc near    ; CODE XREF: calling_convention(void)j
.text:004133C0
.text:004133C0 var_C0          = byte ptr -0C0h
.text:004133C0
.text:004133C0                 push    ebp
.text:004133C1                 mov     ebp, esp
.text:004133C3                 sub     esp, 0C0h
.text:004133C9                 push    ebx
.text:004133CA                 push    esi
.text:004133CB                 push    edi
.text:004133CC                 lea     edi, [ebp+var_C0]
.text:004133D2                 mov     ecx, 30h
.text:004133D7                 mov     eax, 0CCCCCCCCh
.text:004133DC                 rep stosd
.text:004133DE                 push    3               ; __formal
.text:004133E0                 push    2               ; __formal
.text:004133E2                 push    1               ; __formal
.text:004133E4                 call    j_?demo_cdecl@@YAXHHH@Z ; demo_cdecl(int,int,int)
.text:004133E9                 add     esp, 0Ch
.text:004133EC                 push    3               ; __formal
.text:004133EE                 push    2               ; __formal
.text:004133F0                 push    1               ; __formal
.text:004133F2                 call    j_?demo_stdcall@@YGXHHH@Z ; demo_stdcall(int,int,int)
.text:004133F7                 push    3               ; __formal
.text:004133F9                 mov     edx, 2          ; __formal
.text:004133FE                 mov     ecx, 1          ; __formal
.text:00413403                 call    j_?demo_fastcall@@YIXHHH@Z ; demo_fastcall(int,int,int)
.text:00413408                 pop     edi
.text:00413409                 pop     esi
.text:0041340A                 pop     ebx
.text:0041340B                 add     esp, 0C0h
.text:00413411                 cmp     ebp, esp
.text:00413413                 call    j___RTC_CheckEsp
.text:00413418                 mov     esp, ebp
.text:0041341A                 pop     ebp
.text:0041341B                 retn
.text:0041341B ?calling_convention@@YAXXZ endp

经常看到游戏里面的代码 mov edx,xxx  、mov ecx,xxxx  然后call xxxx 原来是fastcall参数来的。


你可能感兴趣的:(反汇编)