How do you use gcc to generate assembly code in Intel syntax?
assembly, gcc, intel-syntax, x86
Solution
Use `-masm=intel`
gcc -S -masm=intel -Og -fverbose-asm test.c
That works with GCC, and Clang 3.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 macOS, note that by default, the `gcc` command actually runs Clang unless you've installed actual GCC (e.g. from Brew). 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.
Problem
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?