I would like to see, after compiling some code (for example C), the resulting code in machine language or assembly. How can that be done?
-
2What system / compiler? – dbush Jun 01 '18 at 15:20
-
Check this site: https://godbolt.org – danglingpointer Jun 01 '18 at 15:29
4 Answers
Many compilers (including gcc
and clang
) have an -S
option that makes them output assembly instead of a binary file.
Alternatively you can view the assembly for an existing binary file using a disassembler. For example objdump
from the GNU binutils can show you the assembly for a given binary using the -d
(--disassemble
) or -D
(--disassemble-all
) options.

- 363,768
- 54
- 674
- 675
From the GCC documentation (assuming gcc) found at https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#Overall-Options:
-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.
For example, gcc -S hello.c
would output an assembly file named hello.s
.

- 680
- 1
- 8
- 11
compile your code with the -g flag, and run with gdb
gcc -g main.c
gdb a.exe
and in gdb:
(gdb) layout asm
There is more info in a related post here

- 1,406
- 2
- 10
- 10
If you're compiling your source code: gcc -S file.c
If you don't have the source code, just the binary file: objdump -d exe

- 2,394
- 1
- 16
- 20