使用 gcc -S 时,生成的汇编采用 AT&T 语法。能否要求输出文件改用 Intel 语法?或者能否把一种语法转换成另一种?
With gcc -S, the resulting assembly uses AT&T syntax, so can I request Intel syntax for the output files instead? Alternatively, can either syntax be converted into the other one?
使用 gcc -S 时,生成的汇编采用 AT&T 语法。能否要求输出文件改用 Intel 语法?或者能否把一种语法转换成另一种?
With gcc -S, the resulting assembly uses AT&T syntax, so can I request Intel syntax for the output files instead? Alternatively, can either syntax be converted into the other one?
传入 -masm=intel
gcc -S -masm=intel -Og -fverbose-asm sample.c
GCC 和从 3.5 开始的 Clang 都支持。GCC manual (https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-masm_003ddialect)。
-masm=dialect 按请求的语法输出汇编指令。可选设置 是 intel 和 att,默认选择 att。Darwin 不支持 Intel。
在 macOS 上要记住,gcc 通常会运行 Clang,除非你另外安装了真正的 GCC(比如通过 Brew)。当前 clang 接受 -masm=intel 作为等价选项,但 clang 一直都接受下面这种写法 (https://stackoverflow.com/a/11957826/950427)。
clang++ -S -mllvm --x86-asm-syntax=intel sample.cpp
要记住,在 clang 14 (https://reviews.llvm.org/D113707) 之前,与 GCC (https://stackoverflow.com/questions/9347909/can-i-use-intel-syntax-of-x86-assembly-with-gcc) 不同,这个选项不会改变 clang 处理内联 asm() 语句的方式。
由 Arden Fenwick 维护的编译器浏览网站 Compiler Explorer 默认使用这些选项。https://godbolt.org/
想了解其他开关以及如何取得有用的汇编列表,可以参阅减少 GCC/clang 汇编输出中的杂项 (https://stackoverflow.com/questions/38552116/how-to-remove-noise-from-gcc-clang-assembly-output)。
Pass -masm=intel
gcc -S -masm=intel -Og -fverbose-asm sample.c
This works in GCC and in Clang starting with 3.5. GCC manual (https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-masm_003ddialect):
-masm=dialect Emit assembly instructions in the requested dialect. The available settings are intel and att, with att selected by default. Intel is unsupported on Darwin.
On macOS, remember that gcc normally invokes Clang, unless you have separately installed GCC itself (through Brew, for instance). Current clang accepts -masm=intel as an equivalent option, but clang has always accepted this (https://stackoverflow.com/a/11957826/950427):
clang++ -S -mllvm --x86-asm-syntax=intel sample.cpp
Remember that before clang 14 (https://reviews.llvm.org/D113707), unlike GCC (https://stackoverflow.com/questions/9347909/can-i-use-intel-syntax-of-x86-assembly-with-gcc), this option leaves clang's handling of inline asm() statements unchanged.
Compiler Explorer, maintained by Arden Fenwick, uses these options as its defaults: https://godbolt.org/
For additional switches and advice on obtaining useful assembly listings, consult Reducing clutter in GCC/clang assembly output (https://stackoverflow.com/questions/38552116/how-to-remove-noise-from-gcc-clang-assembly-output).
这条命令
gcc -S -masm=intel sample.c
在我这里有效。还有另一种方法,不过它与调用 gcc 无关。 先构建可执行文件或目标文件,再让 objdump 按下面的方式用 Intel 汇编语法反汇编该目标文件。
objdump -d --disassembler-options=intel a.out
也许有用。
This command
gcc -S -masm=intel sample.c
Works for me. Another route is possible too, though it doesn't involve invoking gcc. Build an executable or object file first, then ask objdump to disassemble that object using Intel assembly syntax, like this:
objdump -d --disassembler-options=intel a.out
Perhaps that's useful.
我的 CPP 文件内容如下。
#include <conio.h>
#include <stdio.h>
#include <windows.h>
int result = 0;
int main(int count, char *items[]) {
asm("mov eax, 0xEE");
asm("mov _result, eax");
printf("result contains %d\n", result);
getch();
return 0;
};
我用下面这个 GCC 调用让代码运行成功。
gcc.exe Sample.cpp -masm=intel -mconsole -o Sample.exe
输出会是一个 *.exe 文件,在我这里成功运行了。
Remarks:
for an immediate operand, use _variable for a global variable rather than a local one.
exampel: mov _itemCount, eax NOT mov $itemCount, eax or mov itemCount, eax
Hexadecimal numbers require at&t notation instead of intel notation.
example: mov eax, 0xEE -> TRUE, mov eax, 0EEh -> FALSE.
就这些。
Here's what my CPP file contains:
#include <conio.h>
#include <stdio.h>
#include <windows.h>
int result = 0;
int main(int count, char *items[]) {
asm("mov eax, 0xEE");
asm("mov _result, eax");
printf("result contains %d\n", result);
getch();
return 0;
};
I got that code working using this GCC invocation:
gcc.exe Sample.cpp -masm=intel -mconsole -o Sample.exe
The output is an *.exe file, which ran successfully for me.
Remarks:
for an immediate operand, use _variable for a global variable rather than a local one.
exampel: mov _itemCount, eax NOT mov $itemCount, eax or mov itemCount, eax
Hexadecimal numbers require at&t notation instead of intel notation.
example: mov eax, 0xEE -> TRUE, mov eax, 0EEh -> FALSE.
Nothing more.
好吧,这个问题把我绕晕了。Arch 上的 Tcl 9.0,跑的是 tclsh main.tcl,给客户的五金供应网站做的一个小订单报表。 我在 config.tcl 里原本只有一条规则 (total >= 200),一切正常。后来我加了第二条规则,让…
ECMA-262 里压根没提事件循环。它定义的是 job,以及一个叫 HostEnqueuePromiseJob 的宿主钩子,promise 的回调准备好运行时,引擎就调用它。这些 job 到底什么时候运行,它们之间又运行什么,是宿主自己的事。 这就…