_cdecl与_stdcall是最常用的的两种函数调用修饰,区别在于函数返回时,清理栈(恢复栈平衡)是caller做还是被调函数做。
1 4: _cdecl int add1(int a, int b) 2 5: { 3 00401020 push ebp 4 00401021 mov ebp,esp 5 00401023 sub esp,40h 6 00401026 push ebx 7 00401027 push esi 8 00401028 push edi 9 00401029 lea edi,[ebp-40h] 10 0040102C mov ecx,10h 11 00401031 mov eax,0CCCCCCCCh 12 00401036 rep stos dword ptr [edi] 13 6: return a+b; 14 00401038 mov eax,dword ptr [ebp+8] 15 0040103B add eax,dword ptr [ebp+0Ch] 16 7: } 17 0040103E pop edi 18 0040103F pop esi 19 00401040 pop ebx 20 00401041 mov esp,ebp 21 00401043 pop ebp 22 00401044 ret 23 24 9: _stdcall int add2(int a, int b) 25 10: { 26 00401060 push ebp 27 00401061 mov ebp,esp 28 00401063 sub esp,40h 29 00401066 push ebx 30 00401067 push esi 31 00401068 push edi 32 00401069 lea edi,[ebp-40h] 33 0040106C mov ecx,10h 34 00401071 mov eax,0CCCCCCCCh 35 00401076 rep stos dword ptr [edi] 36 11: return a+b; 37 00401078 mov eax,dword ptr [ebp+8] 38 0040107B add eax,dword ptr [ebp+0Ch] 39 12: } 40 0040107E pop edi 41 0040107F pop esi 42 00401080 pop ebx 43 00401081 mov esp,ebp 44 00401083 pop ebp 45 00401084 ret 8