5.1.1 · A language for describing register machines
Controller text names data paths, operations, and control transfers.
Assemble labels and execute assign, test, branch, goto, save, restore, perform, and halt over one explicit register file, stack, and operation table.
Guiding question
What common protocol lets one simulator execute controllers for very different machines?
Represent controller labels separately from executable instructions
Evaluate constant, register, label, and operation sources
Execute assign, test, branch, goto, save, restore, perform, and halt
Keep registers, stack, flag, pc, operations, and instruction count explicit
Bound a machine run without changing the controller
The assembler pass counts only instruction lists and records each label as the position of the next instruction. The machine then stores the stripped instruction sequence, label table, mutable register cells, stack, operation table, pc, flag, halt state, and fetched-instruction count as explicit data.
evaluate-source gives one meaning to const, reg, label, and op forms. execute-one! selects an already assembled instruction and applies the rule for its tag. The Euclid controller uses assignment, testing, branching, a label goto, and perform. The subroutine controller additionally saves and restores a continuation and returns through a register target. The lesson register-machine simulator executes the designated instruction set over explicit machine state.
Follow labels becoming numeric positions before execution. In Euclid, separate the test/branch pair from the seven-instruction reduction cycle. In the subroutine run, locate the saved outer continuation, the temporary double-return address, restore, and the two register-target gotos.
Try it yourself
Change the program and compare the result.
Add an instruction that records the pc before every fetch, then run the Euclid controller with 1071 and 462. Predict the repeated loop segment and final register values.
Show hint
Instrumentation belongs in the simulator loop, not in every controller instruction. The controller itself can remain unchanged.