1 int add1(int a, int b); //缺省调用 2 3 int WINAPI add2(int a, int b); //标准调用 4 5 int main() 6 { 7 int s1, s2; 8 int a = 1, b = 2; 9 10 s1 = add1(a, b); 11 s2 = add2(a, b); 12 13 return 0; 14 } 15 16 int add1(int a, int b) 17 { 18 int c = 0; 19 c = a + b; 20 return c; 21 } 22 23 int WINAPI add2(int a, int b) 24 { 25 int c = 0; 26 c = a + b; 27 return c; 28 }
汇编:
int add1(int a, int b)// _cdecl { 008E16F0 push ebp 008E16F1 mov ebp,esp 008E16F3 sub esp,0CCh 008E16F9 push ebx 008E16FA push esi 008E16FB push edi 008E16FC lea edi,[ebp-0CCh] 008E1702 mov ecx,33h 008E1707 mov eax,0CCCCCCCCh 008E170C rep stos dword ptr es:[edi] 008E170E mov ecx,offset _E8582256_main@cpp (08EC015h) 008E1713 call @__CheckForDebuggerJustMyCode@4 (08E120Dh) int c = 0; 008E1718 mov dword ptr [c],0 c = a + b; 008E171F mov eax,dword ptr [a] 008E1722 add eax,dword ptr [b] 008E1725 mov dword ptr [c],eax return c; 008E1728 mov eax,dword ptr [c] } 008E172B pop edi 008E172C pop esi 008E172D pop ebx 008E172E add esp,0CCh 008E1734 cmp ebp,esp 008E1736 call __RTC_CheckEsp (08E1217h) 008E173B mov esp,ebp 008E173D pop ebp 008E173E ret //此处没有平栈,而是返回后由调用者负责平栈(编译器会自动处理)
int WINAPI add2(int a, int b) //_stdcall { 008E1750 push ebp 008E1751 mov ebp,esp 008E1753 sub esp,0CCh 008E1759 push ebx 008E175A push esi 008E175B push edi 008E175C lea edi,[ebp-0CCh] 008E1762 mov ecx,33h 008E1767 mov eax,0CCCCCCCCh 008E176C rep stos dword ptr es:[edi] 008E176E mov ecx,offset _E8582256_main@cpp (08EC015h) 008E1773 call @__CheckForDebuggerJustMyCode@4 (08E120Dh) int c = 0; 008E1778 mov dword ptr [c],0 c = a + b; 008E177F mov eax,dword ptr [a] 008E1782 add eax,dword ptr [b] 008E1785 mov dword ptr [c],eax return c; 008E1788 mov eax,dword ptr [c] } 008E178B pop edi 008E178C pop esi 008E178D pop ebx 008E178E add esp,0CCh 008E1794 cmp ebp,esp 008E1796 call __RTC_CheckEsp (08E1217h) 008E179B mov esp,ebp 008E179D pop ebp 008E179E ret 8 //在内部平栈
main
int main() { 008E17C0 push ebp 008E17C1 mov ebp,esp 008E17C3 sub esp,0F0h 008E17C9 push ebx 008E17CA push esi 008E17CB push edi 008E17CC lea edi,[ebp-0F0h] 008E17D2 mov ecx,3Ch 008E17D7 mov eax,0CCCCCCCCh 008E17DC rep stos dword ptr es:[edi] 008E17DE mov ecx,offset _E8582256_main@cpp (08EC015h) 008E17E3 call @__CheckForDebuggerJustMyCode@4 (08E120Dh) int s1, s2; int a = 1, b = 2; 008E17E8 mov dword ptr [a],1 008E17EF mov dword ptr [b],2 s1 = add1(a, b); 008E17F6 mov eax,dword ptr [b] s1 = add1(a, b); 008E17F9 push eax 008E17FA mov ecx,dword ptr [a] 008E17FD push ecx 008E17FE call add1 (08E1177h) 008E1803 add esp,8 //调用返回后由编译器在外部平栈 008E1806 mov dword ptr [s1],eax s2 = add2(a, b); 008E1809 mov eax,dword ptr [b] 008E180C push eax 008E180D mov ecx,dword ptr [a] 008E1810 push ecx 008E1811 call add2 (08E1145h) 008E1816 mov dword ptr [s2],eax return 0; 008E1819 xor eax,eax } 008E181B pop edi 008E181C pop esi 008E181D pop ebx 008E181E add esp,0F0h 008E1824 cmp ebp,esp 008E1826 call __RTC_CheckEsp (08E1217h) 008E182B mov esp,ebp 008E182D pop ebp 008E182E ret