[英]The -masm=intel flag is not working for running assembly language in gcc compiler with Intel syntax
我試圖在我的 C 程序中使用內聯匯編器 __asm 與 Intel 語法而不是 AT&T 語法。 我正在使用gcc -S -masm=intel test.c
編譯,但它給出了錯誤。 下面是我的 test.c 文件。
#include <stdio.h>
//using namespace std;
int AsmCode(int num,int power) {
__asm {
mov eax, num;
mov ecx, power;
shl eax, cl;
};
}
int main()
{
printf("eax value is %d\n",AsmCode(2,3));
//getchar();
return 0;
}
預期結果是 eax 值是 16,但出現了未知類型名稱“mov”、未知類型名稱“shl”等錯誤。
編輯:我已將代碼更新為:
int AsmCode(int num,int power) {
__asm__ (
"movl eax, num;"
"mov ecx, power;"
"shl eax, cl;"
);
}
int main()
{
printf("eax value is %d\n",AsmCode(2,3));
return 0;
}
並使用gcc -S -masm=intel test.c
編譯此代碼。 這導致NO OUTPUT ,而它應該產生輸出,因為eax value is 16
。
當用gcc test.c
編譯時,它產生了錯誤:
Error: too many memory references for 'mov'
Error: too many memory references for 'shl'
請幫忙..
最重要的錯誤是第一個:
main.cpp:4:11: error: expected '(' before '{' token
__asm {
^
(
您對 GCC 使用了錯誤的語法。 您已經使用過 Microsoft Visual Studio 語法。 因此,您的 GCC 不知道您正在嘗試為其提供組裝說明。
而不是__asm { ... }
,它應該是__asm__ ( "..." )
。
像這樣:
int AsmCode(int num,int power) {
__asm__ (
"mov eax, num;"
"mov ecx, power;"
"shl eax, cl;"
);
}
在這里閱讀更多。
請注意,您的 ASM 還存在其他問題,您應該單獨詢問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.