- 最後登錄
- 2012-10-12
- 在線時間
- 221 小時
- 註冊時間
- 2007-10-18
- 閱讀權限
- 95
- 精華
- 3
- UID
- 2593154
- 帖子
- 802
- 積分
- 2980 點
- 潛水值
- 27720 米
| 如果你忘記伊莉的密碼,請在登入時按右邊出現的 '找回密碼'。輸入相關資料後送出,系統就會把密碼寄到你的E-Mail。 本帖最後由 Force[TW] 於 2009-11-26 08:16 PM 編輯
微軟 Visual Studio 的編譯器所使用的 asm 語法是(Intel 的方法):
參考資料(MSDN):- // IDE: Visual C++
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- void main(void)
- {
- int a = 15, b = 0, adder = 240;
- cout<<"a = "<<a<<endl;
- cout<<"b = "<<b<<endl;
- __asm
- {
- // eax = a
- mov eax, a;
- // eax += adder
- add eax, adder;
- // b = eax
- mov b, eax;
- }
- cout<<"a = "<<a<<endl;
- cout<<"b = "<<b<<endl;
- system("PAUSE");
- }
複製代碼 但是 GCC 編譯工具(AT&T 的方法;Unix)所使用的 asm 語法是不同於微軟的編譯環境:
參考資料(CodeProject.com):
所以 Dev-C++ 僅適用於 AT&T 的方法!- // asm 語法
- // asm ("敘述式");
- asm ("statements");
- __asm__("statements");
- //
- // asm 延伸語法
- // asm ( "敘述式" : 輸出 : 輸入 : clobbered);
- /* clobbered - comma separated list of registers clobbered.
- If you write to memory then "memory" has to inluded as one of the clobbered values. This is to tell gcc that we might have changed some value in the memory which gcc thought it had in a register, It is equivalent to clobbering all of the registers. */
- // 疑問:clobbered 強制寫入?!
- asm ( "statements" : output : input : clobbered);
- //
- // 以下是參數:
- The constraints for input/output are :-
- g - let the compiler decide which register to use for the variable
- q - load into any available register from eax, ebx, ecx, edx
- r - same as q but includes esi and edi
- a - load into the eax register
- b - load into the ebx register
- c - load into the ecx register
- d - load into the edx register
- f - load into the floating point register
- D - load into the edi register
- S - load into the esi register
複製代碼 ... |
|