TAOCP Vol 1: Fundamental Algorithms · Week 32
TAOCP 1.4.3 Interpretive Routines: reading guide
Interpreters written in MIX, culminating in a MIX simulator written in MIX itself and a trace routine that watches a program run. It covers decoding, dispatch, and the cost of interpretation.
Time About 8 hours this week
Why it matters
You built two interpreters in weeks 1 to 16. This section is the same idea at the machine level, and the trace routine is the ancestor of every debugger.
Before you start
- 1.4.1 Subroutines
- Crafting Interpreters (clox dispatch loop)
How to approach it
Map each part of Knuth's simulator to the matching part of your clox run() loop: fetch, decode, dispatch, execute. Read the simulator code slowly; it is long. The trace routine section is worth reading closely for how it intercepts each instruction.
Exercises
Do the 00 to 15 exercises to make sure you can read MIX fluently. Then write and actually run at least two of the 20-ish programming exercises in a MIX simulator (GNU MDK works). Reading assembly is not the same as writing it; the bugs you hit are the lesson.
Traps
- Trying to understand every line of the simulator in one sitting. Go routine by routine.