Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent asm code for C/C++ codes [duplicate]

Possible Duplicate:
How do you get assembler output from C/C++ source in gcc?

Hello out there!

I have a C and C++ source code that I wanted to see in assembly code. How can I produce an equivalent asm codes for those? What tools should I use? Or is it already possible in using tools such as the gcc compiler? Then what commands should I execute? I prefer tools on top of Linux particularly Ubuntu.

Thanks in advance!

like image 800
neilmarion Avatar asked Jan 20 '26 14:01

neilmarion


1 Answers

gcc -S x.c

This should produce the assembly that gcc thinks is equivalent to your code. Beware though, the optimizer can do some very tricky things which may be hard to see are functionally equivalent to your code. Especially in c++ where the optimizer is so dependent on inlining and stuff like that.

From the gcc man page:

-S

Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified. By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with .s.

Input files that don't require compilation are ignored.

like image 117
Evan Teran Avatar answered Jan 22 '26 05:01

Evan Teran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!