用VC写Assembly代码(3)
不知為什么,對這種編程方法越來越大越有興趣.先寫個使用參數的例子(十分簡單,適用于任何懂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
總結
以上是生活随笔為你收集整理的用VC写Assembly代码(3)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php怎么运行网页_PHP的作用是什么?
- 下一篇: ps意外崩溃_充满意外的数学中考