Bob
Bob

Reputation: 2616

Easy way to convert c code to x86 assembly?

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.

Upvotes: 20

Views: 35920

Answers (9)

kennytm
kennytm

Reputation: 523774

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

Edit: If your program is pretty short, you could use the online service at https://gcc.godbolt.org/.

Upvotes: 4

yoavstr
yoavstr

Reputation: 387

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

Upvotes: 0

Vineel Kumar Reddy
Vineel Kumar Reddy

Reputation: 4726

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

cl /FAs a.c

Upvotes: 0

SoapBox
SoapBox

Reputation: 20609

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

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

Upvotes: 46

BCS
BCS

Reputation: 78683

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.

Upvotes: 0

Norman Ramsey
Norman Ramsey

Reputation: 202725

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.

Upvotes: 7

D.C.
D.C.

Reputation: 15588

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

Upvotes: 1

James McNellis
James McNellis

Reputation: 355357

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.

Upvotes: 13

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

Upvotes: 14

Related Questions