我可以在 GCC 中使用英特尔 x86 程序集语法吗? [英] Can I use Intel syntax of x86 assembly with GCC?

查看:19
本文介绍了我可以在 GCC 中使用英特尔 x86 程序集语法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个小的低级程序.对于其中的某些部分,我需要使用汇编语言,但其余代码将使用 C/C++ 编写.

I want to write a small low level program. For some parts of it I will need to use assembly language, but the rest of the code will be written on C/C++.

那么,如果我将使用 GCC 将 C/C++ 与汇编代码混合在一起,我是否需要使用 AT&T 语法或可以我使用英特尔语法?或者您如何以其他方式混合 C/C++ 和 asm(英特尔语法)?

So, if I will use GCC to mix C/C++ with assembly code, do I need to use AT&T syntax or can I use Intel syntax? Or how do you mix C/C++ and asm (intel syntax) in some other way?

我意识到也许我别无选择,必须使用 AT&T 语法,但我想确定..

I realize that maybe I don't have a choice and must use AT&T syntax, but I want to be sure..

如果事实证明别无选择,我在哪里可以找到有关 AT&T 语法的完整/官方文档?

And if there turns out to be no choice, where I can find full/official documentation about the AT&T syntax?

谢谢!

推荐答案

如果你使用单独的汇编文件,gas 有一个指令来支持 Intel 语法:

If you are using separate assembly files, gas has a directive to support Intel syntax:

.intel_syntax noprefix

它使用 Intel 语法并且不需要在寄存器名称前加上 % 前缀.

which uses Intel syntax and doesn't need the % prefix before register names.

(您也可以使用 -msyntax=intel -mnaked-reg 运行 as 以将其作为默认值而不是 att,在如果您不想将 .intel_syntax noprefix 放在文件顶部.)

(You can also run as with -msyntax=intel -mnaked-reg to have that as the default instead of att, in case you don't want to put .intel_syntax noprefix at the top of your files.)

如果您使用内联汇编,则可以使用 gcc -masm=intel 编译 C/C++ 源代码(请参阅 如何设置 gcc 以永久使用 intel 语法? 了解详情.)这可能不适用于 clang.

If you are using inline assembly, you can compile your C/C++ sources with gcc -masm=intel (See How to set gcc to use intel syntax permanently? for details.) This may not work with clang.

在内联 asm 的开头使用 .intel_syntax noprefix,然后用 .att_syntax 切换回来可以工作,但如果你使用 会中断任何 m 约束.内存引用仍将以 AT&T 语法生成.

Using .intel_syntax noprefix at the start of inline asm, and switching back with .att_syntax can work, but will break if you use any m constraints. The memory reference will still be generated in AT&T syntax.

这篇关于我可以在 GCC 中使用英特尔 x86 程序集语法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆