不知为什么,对这种编程方法越来越大越有兴趣.先写个使用参数的例子(十分简单,适用于任何懂C的人)给各位参考一下吧:
#include <stdio.h>
int asm(int s)
{
int t=0;
__asm
{
mov eax, DWORD PTR [ebp+8] ;把s的值传给eax
mov t, eax ;把eax的值传给t
}
printf("- %d -", t);//把T显示出来
}
void main()
{
asm(100);
}
我调试这个程序,得出以下汇编代码:
3: int asm(int s)
4: {
0040B4B0 push ebp
0040B4B1 mov ebp,esp
0040B4B3 sub esp,44h
0040B4B6 push ebx
0040B4B7 push esi
0040B4B8 push edi
0040B4B9 lea edi,[ebp-44h]
0040B4BC mov ecx,11h
0040B4C1 mov eax,0CCCCCCCCh
0040B4C6 rep stos dword ptr [edi]
5: int t=0;
0040B4C8 mov dword ptr [ebp-4],0
6: __asm
7: {
8: mov eax, DWORD PTR [ebp+8] ;把s的值传给eax
0040B4CF mov eax,dword ptr [ebp+8]
9: mov t, eax ;把eax的值传给t
0040B4D2 mov dword ptr [ebp-4],eax
10: }
11: printf("- %d -", t);//把T显示出来
0040B4D5 mov eax,dword ptr [ebp-4]
0040B4D8 push eax
0040B4D9 push offset string "%d====" (0041ff3c)
0040B4DE call printf (0040b790)
0040B4E3 add esp,8
12: }
0040B4E6 pop edi
0040B4E7 pop esi
0040B4E8 pop ebx
0040B4E9 add esp,44h
0040B4EC cmp ebp,esp
0040B4EE call __chkesp (0040b470)
0040B4F3 mov esp,ebp
0040B4F5 pop ebp
0040B4F6 ret