Master the fundamental concepts of code generation through this focused micro-challenge.
The final backend maps IR operations to machine instructions. Clang's x86 backend and GCC's rtx emission translate add to addl, spills temporaries to stack slots, and follow the System V AMD64 ABI for calling conventions.
Each IR opcode maps to one or more assembly instructions. Loads from variables become mov from memory. Adds become add between registers. Compare and branch become cmp + je/jne.
asmLoading…
Production compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will generate x86 assembly from your IR. This exercise asks you to map arithmetic, moves, and branches to assembly syntax and manage register and stack operands for a simple instruction subset.
Implement x86 assembly generation from three-address code.
Implement instruction selection:
Generate code for:
Handle operand types:
$42 (immediate)-4(%ebp) (stack offset) or var_name (global)Output valid assembly:
gcc or nasmThree hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github