VC++中的函数调用惯例
2010-08-15 20:47:34 来源:WEB开发网从以上调用Input函数的过程可以看出 :在调用此函数之前,首先压栈ebp-8,然后压栈ebp-4,然后调用函数Input,在调 用函数Input之后,没有相应的堆栈恢复工作(为其它的函数调用,所以我没有列 出)
下面再列出Input函数本身的汇编代码:(实际此函数不大,但做汇编 例子还是大了些,大家可以只看前和后,中间代码与此例子无关)
39: void WINAPI Input( int &m,int &n)
40: {
00401110 push ebp
00401111 mov ebp,esp
00401113 sub esp,48h
00401116 push ebx
00401117 push esi
00401118 push edi
00401119 lea edi,[ebp-48h]
0040111C mov ecx,12h
00401121 mov eax,0CCCCCCCCh
00401126 rep stos dword ptr [edi]
41: int s,i;
42:
43: while(1)
00401128 mov eax,1
0040112D test eax,eax
0040112F je Input+0C1h (004011d1)
44: {
45: printf("\nPlease input the first number m:");
00401135 push offset string "\nPlease input the first number m"... (004260b8)
0040113A call printf (00401530)
0040113F add esp,4
46: scanf("%d",&m);
00401142 mov ecx,dword ptr [ebp+8]
00401145 push ecx
00401146 push offset string "%d" (004260b4)
0040114B call scanf (004015f0)
00401150 add esp,8
47:
48: if ( m= s )
004011B3 mov eax,dword ptr [ebp+8]
004011B6 mov ecx,dword ptr [eax]
004011B8 cmp ecx,dword ptr [ebp-4]
004011BB jl Input+0AFh (004011bf)
57: break;
004011BD jmp Input+0C1h (004011d1)
58: else
59: printf(" m < n*(n+1)/2,Please input again!\n");
004011BF push offset string " m < n*(n+1)/2,Please input agai"... (00426060)
004011C4 call printf (00401530)
004011C9 add esp,4
60: }
004011CC jmp Input+18h (00401128)
61:
62: }
004011D1 pop edi
004011D2 pop esi
004011D3 pop ebx
004011D4 add esp,48h
004011D7 cmp ebp,esp
004011D9 call __chkesp (004015b0)
004011DE mov esp,ebp
004011E0 pop ebp
004011E1 ret 8
更多精彩
赞助商链接