Free to Learn Interactive courses
Compiler engineering

Register Allocator & Spill Lab

A register is a fast slot inside the processor. Decide which values stay there and which spill into memory.

8 lessonsInteractive lab
Four small register slots on the processor chip connect to a separate memory bank.

1 · The big idea
2 · Worked step-by-step example

3 · Interactive workbench (explore before quizzing)

Allocator lab

Live model
Course guide

Build a compiler register allocator & graph-coloring spill lab

For programmers who can follow a small loop. A compiler chooses where each value lives as it turns code into instructions. In this lab you make those choices, inspect the record, and repair a new loop.

Using the lab

Start with the picture, make a prediction, then change one thing in the workbench. Each lesson opens independently. The program editor accepts new examples and reports errors beside the source.

What the counter measures

The model counts reads and writes to memory. It charges one read per distinct spilled input and one write per spilled result per instruction, plus explicit memory operations. Each loop level multiplies the modeled visit count by ten. A spilled input can use a memory operand or a temporary outside the four assigned registers. The total estimates memory traffic.

Your work

Predictions stay in this browser when local storage is available. Download a copy to keep your answers and edits.