我有C程序和装配插入。下面是代码: main.c:
#include <stdio.h>
int f() {
int a = 0, b;
__asm__ (".intel_syntax noprefix\n\t"
"mov edx, 1\n\t"
:"=r"(b)
:"r"(a)
:"eax"
);
return b;
}
int main() {
printf("%d", f());
}我已经了解了如何编译这段代码(gcc -std=c11 -S main.c -o main),但是当我运行它时(./main) --这是终端中的一个问题: bash:./main:权限被拒绝。
当我试图在没有-S标志的情况下编译它时,我会遇到许多不合理的错误:
/tmp/ccw3H0Mb.s: Assembler messages:
/tmp/ccw3H0Mb.s:23: Error: Instruction does not exist: «movl%edx,-4(%rbp)»
/tmp/ccw3H0Mb.s:24: Error: Instruction does not exist: «movl4(%rbp),%eax»
/tmp/ccw3H0Mb.s:46: Error: Instruction does not exist: «movl$0,%eax»
/tmp/ccw3H0Mb.s:48: Error: Instruction does not exist: «movl%eax,%esi»
/tmp/ccw3H0Mb.s:49: Error: Garbage «(%rip)» after expression
/tmp/ccw3H0Mb.s:50: Error: Instruction does not exist: «movl$0,%eax»
/tmp/ccw3H0Mb.s:52: Error: Instruction does not exist: «movl$0,%eax»什么是错误,如何修复它才能正确运行我的代码?谢谢!:)
发布于 2020-11-02 21:11:29
我所需要的只是将-masm=intel添加到编译命令中,当然,我删除了-S标志(感谢fuz)。这是很重要的,因为我正在使用英特尔语法,所以gcc必须意识到它。
现在看起来是:
gcc -std=c11 -masm=intel main.c -o mainhttps://stackoverflow.com/questions/64652675
复制相似问题