← back to programming

Register Machines

Abelson & Sussman · 1996 · SICP §5.1

Abstract machines with named registers, a controller, and explicit data paths. Every high-level operation eventually becomes register transfers. This is where software meets hardware.

controller instructions ALU val argl continue registers hold data, the controller sequences operations

A language for describing register machines

A register machine has a fixed set of registers (named storage cells), a controller (sequence of instructions), and operations (primitive computations). Instructions assign to registers, test conditions, and branch. The controller is a flat list of labeled instructions — the assembly language of our abstract machine.

Scheme

Abstraction in machine design

Complex machines are built from simpler ones. A GCD machine that takes input and produces output can be a subroutine inside a larger machine. The key abstraction: a machine's interface is its registers (inputs and outputs), not its controller.

Scheme

Subroutines and the stack

When a machine calls a subroutine, it must remember where to return. A stack saves and restores register values. save pushes a register onto the stack; restore pops it back. The stack is the mechanism that makes subroutines — and recursion — possible at the machine level.

Scheme

Recursive machines — factorial

A recursive procedure becomes a register machine that saves its state on the stack before each recursive call and restores it after. The controller has the same structure as the recursive procedure, but call and return are explicit stack operations.

Scheme

Recursive machines — Fibonacci

Fibonacci is harder than factorial because it makes two recursive calls. The stack must save enough state to resume after each one. This is the register-machine version of the tree-recursive process from Chapter 2.

Scheme

Notation reference

Register machine Python Meaning
(assign reg (op f) ...)reg = f(...)Store operation result in register
(test (op =) (reg a) (const 0))if a == 0:Test a condition
(branch (label done))goto / breakConditional jump
(save reg) / (restore reg)stack.append / stack.popPush/pop the stack
(goto (label start))while True / continueUnconditional jump
Neighbors

Other reading pages

Foundations (Wikipedia)

Translation notes

Register machines strip away all the abstraction that high-level languages provide. Every variable becomes a named register. Every function call becomes a stack save, jump, and restore. Python's call stack is exactly the hardware mechanism being described here — the language just hides it. The register machine notation is essentially assembly language with Lisp syntax. Understanding this layer explains why stack overflows happen, why tail calls matter, and what a compiler actually has to produce.

Ready for the real thing? Read SICP §5.1.