_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,10h11 00401031 mov eax,0CCCCCCCCh12 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 edi18 0040103F pop esi19 00401040 pop ebx20 00401041 mov esp,ebp21 00401043 pop ebp22 00401044 ret23 24 9: _stdcall int add2(int a, int b)25 10: {26 00401060 push ebp27 00401061 mov ebp,esp28 00401063 sub esp,40h29 00401066 push ebx30 00401067 push esi31 00401068 push edi32 00401069 lea edi,[ebp-40h]33 0040106C mov ecx,10h34 00401071 mov eax,0CCCCCCCCh35 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 edi41 0040107F pop esi42 00401080 pop ebx43 00401081 mov esp,ebp44 00401083 pop ebp45 00401084 ret 8