带有GCC的内联组件
Inline Assembly with GCC
#include <stdio.h>
int
get_random(void)
{
asm(".intel_syntax noprefixn"
"mov eax, 42 n");
asm("mov eax, 42 n");
}
int
main(void)
{
return printf("The answer is %d.n", get_random());
}
我正在尝试使用以下CLI命令编译此C++程序:g++ asm.cpp -o asm
错误消息:
/tmp/ccXHbaRO.s: Assembler messages:
/tmp/ccXHbaRO.s:41: Error: no such instruction: `movl %eax,%esi'
/tmp/ccXHbaRO.s:42: Error: no such instruction: `movl $.LC0,%edi'
/tmp/ccXHbaRO.s:43: Error: no such instruction: `movl $0,%eax'
因为我添加了asm(".intel_syntax noprefixn");
,我想我不需要添加GCC标志-masm=intel
?
此外,我在哪里可以找到有关-masm
标志的更多信息?有NASM的等效物吗?
您在汇编中编写的代码会逐字逐句地放在编译器的输出中。
这意味着,如果更改格式或其他有关如何解析程序集代码的全局选项,则需要在最后恢复默认选项。
如果你不这样做,编译器在你的部分之后生成的代码将变得无效。
相关文章:
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 如何将 txt 文件中的行分隔为组件C++
- 奇怪的结构&GCC&clang(void*返回类型)
- GCC本机矩阵运算库
- PowerPC ppc64le上的Gcc Woverloaded虚拟错误
- gcc和c++17的过载解析失败
- 数据成员SFINAE的C++17测试:gcc vs clang
- GCC对可能有效的代码抛出init list生存期警告
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 为什么与常规GCC不同,即使有"学究性错误",MinGW-GCC也能容忍丢失的返回类型
- 使用gcc从静态链接的文件中查找可选符号
- 普通环路未使用gcc 4.8.5自动矢量化
- 有了gcc,是否可以链接库,但前提是它存在
- 在clang++预处理器中确定gcc工具链版本
- 为什么 gcc 编译这个而 msvc 没有
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- 我可以检测和更改 gcc/g++ 中结构的当前数据对齐设置吗?
- 为什么 gcc 会产生这种奇怪的组件与叮当声?
- 带有GCC的内联组件