views:

4548

answers:

3

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?

A: 

Unfortunately gcc can't do this and conversion is difficult because some instructions in AT&T take operands in the same order as Intel, so you have to special case. In addition, some conversions for size where memory dereferencing and such can be difficult. Your best bet is to use a disassembler that will do what you want and make sure you reference symbol files and such. This'll get you 99% of the way.

Cody Brocious
Sounds like someone should add an option for this to gcc seeing as it's free software and all.
Jason Dagit
Good luck. Binutils (the component that handles all of this) is quite possibly the worst piece of software in the world to work with. Biggest mess of arcane, black voodoo code ever written.
Cody Brocious
This may be a wrong answer - one should check Dagit's answer below for a working solution.
romandas
This is definitely wrong. @hyperlogic, you should change the accepted answer
Nathan Fellman
+24  A: 

Have you tried this?

gcc -S -masm=intel test.c

Untested, but I found it in this forum where someone claimed it worked for them.

I just tried this on the mac and it failed, so I looked in my man page:

   -masm=dialect
       Output asm instructions using selected dialect.  Supported choices
       are intel or att (the default one).  Darwin does not support intel.

It may work on your platform.

I also see this sed script which is not perfect, but may work for you.

Jason Dagit
-masm=intel works on my debian/i386.
Jichao
Confirmed to work on Ubuntu Karmic x64 as well.
Thomas
Worked on my MingGW 3.4.5. Many thanks!
Michael Burr
+1  A: 

Try:

gcc code.c -S -masm=intel

Jason Dagit's suggestion works.