我有带有汇编插入的 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: Permission否认。
当我尝试在没有 -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»
错误是什么?如何修复它以正确运行我的代码?谢谢!:)