views:

545

answers:

9

Is there an easy way (like a free program) that can covert c/c++ code to x86 assembly?

I know that any c compiler does something very similar and that I can just compile the c code and then disassemble the complied executable, but that's kind of an overkill, all I want is to convert a few lines of code.

Does anyone know of some program that can do that?

EDIT: I know that GCC compiler does that but it's AT&T syntax and I'm looking for the Intel syntax (not sure if it's called intel syntax or not). The AT&T syntax looks a bit like gibberish to me and some commands use operands in reverse order and not how I'm used to and it can get really confusing.

+5  A: 

Gcc can do it with the -S switch, but it will be disgustingly ugly at&t syntax.

Longpoke
But you can add the `-masm=intel` switch
Nathan Fellman
+7  A: 

gcc will generate assembly if you pass it the -S option on the command line.

Microsoft Visual C++ will do the same with the /FAs option.

James McNellis
Bob
@Bob: VC++ emits beautiful Intel syntax assembly.
James McNellis
@Bob: You may also be able to get gcc to generate Intel syntax assembly: http://stackoverflow.com/questions/199966/how-do-you-use-gcc-to-generate-assembly-code-in-intel-syntax
James McNellis
+1  A: 

if you are using gcc as a compiler, you can compile with the -S option to produce assembly code. see http://www.delorie.com/djgpp/v2faq/faq8_20.html

darren
+1  A: 

Your compiler is already doing that as you've stated, and most likely will have an option to stop before assembling.

For GCC, add the -S flag.

gcc -S x.c
cat x.s
KennyTM
+4  A: 

The lcc compiler is a multiplatform cross-compiler. You can get it to produce Intel syntax assembly code by

lcc -S -Wf-target=x86/win32 foo.c

I find assembly code from lcc significantly easier to read than what gcc spits out nowawadays.

Norman Ramsey
A: 

As many people point out most compilers will do that. If you don't like the syntax,a bit of work with awk or sed should be able to translate. Or I'd be surprised if there wasn't a program that did that bit for you already written somewhere.

BCS
+15  A: 

GCC can output Intel syntax assembly using the following command line:

gcc -S input.c -o output.asm -masm=intel
SoapBox
A: 

In VC++ the following command can be used to list the assembly code.

cl /FAs a.c

Vineel Kumar Reddy
A: 

notice every architecture has its own unique names and even build differently now when you know the stacks involved using asm _volatile_ would b the perfect solution

yoavstr