Quiz Entry - updated: 2026.06.23
How do you compile C to assembly and examine the output?
Use gcc -S to stop after the compile stage and produce a .s assembly file — add -O1/-O2 to see optimized code.
This is the everyday workflow for understanding how C maps to machine instructions, and the basis of tools like Compiler Explorer.
gcc -S program.c # unoptimized assembly
gcc -S -O1 program.c # optimized
gcc -S -O2 -fverbose-asm prog.c # annotate which C variable each line uses
gcc -S -masm=intel program.c # Intel syntax
Compiler Explorer (godbolt.org) lets you do this interactively in a browser and compare compilers and flags side by side — invaluable for learning.
Reading the output:
- Labels ending in
:are function names or jump targets. .L-prefixed labels are compiler-generated locals.- Directives like
.section,.globl,.typeare instructions to the assembler, not real code. - Focus on the instructions between a function label and its
ret.
Tip: add -fno-asynchronous-unwind-tables to strip the .cfi_* directives and get much cleaner output when you're just trying to read the logic.