Master the fundamental concepts of code generation through this focused micro-challenge.
Every compiled function needs a prologue to set up the stack frame and an epilogue to tear it down. x86-64 SysV ABI: push rbp; mov rbp, rsp; sub rsp, N in prologue; mov rsp, rbp; pop rbp; ret in epilogue. Clang and GCC emit these around every function body.
Save caller's frame pointer. Establish new frame pointer. Allocate space for locals and spilled registers. On return, reverse the sequence and restore callee-saved registers.
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 function prologue and epilogue assembly. This exercise asks you to emit stack frame setup and teardown instructions that bracket the function body per the target ABI.
Implement complete function calling code generation.
Generate function prologue:
Generate function epilogue:
Handle function calls (caller side):
Handle parameters (callee side):
Handle local variables:
Three 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