The gcc -S
option will generate assembly code in AT&T syntax, is there a way to generate files in Intel syntax? Or is there a way to convert between the two?
3 Answers
Use -masm=intel
gcc -S -masm=intel -Og -fverbose-asm test.c
That works with GCC, and clang3.5 and later. GCC manual:
-masm=dialect
Output asm instructions using selected dialect. Supported choices are intel or att (the default one). Darwin does not support intel.
For Mac OSX, note that by default, the gcc
command actually runs clang. Modern clang supports -masm=intel
as a synonym for this, but this always works with clang:
clang++ -S -mllvm --x86-asm-syntax=intel test.cpp
Note that until clang 14, this does not change how clang processes inline asm()
statements, unlike for GCC.
These are the options used by Matt Godbolt's Compiler Explorer site by default: https://godbolt.org/
See also How to remove "noise" from GCC/clang assembly output? for other options and tips for getting asm output that's interesting to look at.
-
Despite its incorrect filename att2intel.sed, that sed script converts the other way, from Intel to ATT. Jun 28, 2011 at 20:54
-
-
Clang cannot currently consume Intel syntax. See LLVM Bug 24232: [X86] Inline assembly operands don't work with .intel_syntax. Also, Clang ignores
prefix
/noprefix
(not sure if it matters if Clang consumes the assembly).– jwwSep 26, 2015 at 22:34 -
The
gcc -S -masm=intel test.c
Does work with me. But i can tell another way, although this has nothing to do with running gcc. Compile the executable or the object code file and then disassemble the object code in Intel asm syntax with objdump as below:
objdump -d --disassembler-options=intel a.out
This might help.
-
6
I have this code in CPP file:
#include <conio.h>
#include <stdio.h>
#include <windows.h>
int a = 0;
int main(int argc, char *argv[]) {
asm("mov eax, 0xFF");
asm("mov _a, eax");
printf("Result of a = %d\n", a);
getch();
return 0;
};
That's code worked with this GCC command line:
gcc.exe File.cpp -masm=intel -mconsole -o File.exe
It will result *.exe file, and it worked in my experience.
Notes:
immediate operand must be use _variable in global variabel, not local variable.
example: mov _nLength, eax NOT mov $nLength, eax or mov nLength, eax
A number in hexadecimal format must use at&t syntax, cannot use intel syntax.
example: mov eax, 0xFF -> TRUE, mov eax, 0FFh -> FALSE.
That's all.
-
Doesn't work on my Fedora:
$ gcc -S -masm=intel -mconsole a.c -o a.out gcc: error: unrecognized command line option ‘-mconsole’
– d33tahOct 3, 2015 at 10:26 -
Works in cygwin. Assembly goes in as intel, comes out as intel in the .s file. If you use
-o a.out
you won't get an .s file. Jul 19, 2016 at 23:37 -
3This is a broken way to use inline asm, and will break with optimization enabled. You modify
eax
anda
in asm statements without telling the compiler about it. See stackoverflow.com/tags/inline-assembly/info for guides.-masm=intel
is the correct option to make the syntax inside the asm templates work, but using Basic asm instead of Extended with constraints is very wrong. Nov 3, 2020 at 3:01
echo "packsswb mm0,[bp+si-0x54]" | llvm-mc-3.2 -x86-asm-syntax=intel
givespacksswb -84(%bp,%si), %mm0