As this question shows, with g++, I can do g++ -S -masm=intel test.cpp
.
Also, with clang, I can do clang++ -S test.cpp
, but -masm=intel
is not supported by clang (warning argument unused during compilation: -masm=intel
). How do I get intel syntax with clang?
Asked
Active
Viewed 7.1k times
77

Community
- 1
- 1

Jesse Good
- 50,901
- 14
- 124
- 166
-
@JerryCoffin: Thanks, I generated a `.bc` file with clang and then sucessfully output the Intel assembly with `llc`. Mind making that an answer? – Jesse Good Jun 12 '12 at 03:39
3 Answers
128
As noted below by @thakis, newer versions of Clang (3.5+) accept the -masm=intel
argument.
For older versions, this should get clang to emit assembly code with Intel syntax:
clang++ -S -mllvm --x86-asm-syntax=intel test.cpp
You can use -mllvm <arg>
to pass in llvm options from the clang command line. Sadly this option doesn't appear to be well documented, and thus I only found it by browsing through the llvm mailing lists.

Brennan Vincent
- 10,736
- 9
- 32
- 54

dcoles
- 3,785
- 2
- 28
- 26
-
3http://llvm.org/bugs/show_bug.cgi?id=17465 requests support for -masm=intel and beyond. – Trass3r Oct 22 '13 at 15:30
-
@dcoles Not working for clang 3.7. I executed `$clang -S -mllvm --x86-asm-syntax=intel file.c`. Am I doint something wrong here? It's not giving any error and silently exiting. – S S Aug 06 '15 at 16:28
-
1@saumya-suhagiya I've just confirmed that this still works with clang 3.8.0-svn244195-1~exp1. The command shown above will generate a file called `test.s`. You change this output location to a custom location using the `-o
` option. – dcoles Aug 06 '15 at 16:58 -
1@dcoles Hi, perhaps a not so smart question. Is it possible to compile and link the assembly code with `nasm`? – Alexander Cska Jan 29 '16 at 21:55
-
1@AlexanderCska I'm not sure this is possible without some manual fixup. While the syntax for NASM is similar to Intel's, there is some incompatibilities between them. – dcoles Feb 02 '16 at 23:20
50
As of clang r208683 (clang 3.5+), it understands -masm=intel
. So if your clang is new enough, you can just use that.

thakis
- 5,405
- 1
- 33
- 33
-
It seems to me that the code generated by `-masm=intel` cannot be compiled by `clang` again? I am running clang 3.8. – Yai0Phah Jun 12 '19 at 11:56
17
Presuming you can have Clang emit normal LLVM byte codes, you can then use llc to compile to assembly language, and use its --x86-asm-syntax=intel
option to get the result in Intel syntax.

Kerrek SB
- 464,522
- 92
- 875
- 1,084

Jerry Coffin
- 476,176
- 80
- 629
- 1,111
-
Thanks again. I also found out `llc` by default turns optimizations on (-02) while gcc and clang use no optimizations (-O0) by default (it took me forever to figure out why the assembly output was different). – Jesse Good Jun 12 '12 at 04:18