LOGBOOK

HELP

Quiz Entry - updated: 2026.07.10

How do you compile C to assembly and examine the generated or compiled machine code?

Use gcc -S to emit assembly text from C source, or objdump -d / GDB's disassemble to read the machine code back out of a compiled binary.

There are two directions, and both are essential for reverse engineering practice:

Forward — C to assembly text:

gcc -S -O2 example.c          # produces example.s (AT&T syntax)
gcc -S -O2 -m32 example.c     # 32-bit (IA32) assembly
gcc -S -O2 -masm=intel example.c   # Intel syntax instead of AT&T

Backward — disassemble a built binary:

objdump -d example     # disassemble the .text (code) section
objdump -D example     # disassemble ALL sections (incl. data)

Interactively, in GDB:

gdb ./example
(gdb) disassemble main      # show main's instructions
(gdb) x/10i main            # examine 10 instructions at main
(gdb) x/7xg 0x4005c8        # 7 hex giant-words (e.g. a jump table)

Useful flags: -O0-O3 set optimization level (higher = less recognizable mapping to source); -fno-omit-frame-pointer keeps %rbp as a frame pointer to ease debugging.

Tip: Compare the same code at -O0 and -O2 — the optimized version reveals the compiler tricks (inversion, lea arithmetic, pointer-walking loops) covered in this topic.

Go deeper:

From Quiz: REVE1 / Translation of C to Assembly | Updated: Jul 10, 2026