Week 31 of 125
TAOCP 1.4.1 and 1.4.2
Sign up or sign in to tick these off and give this week a due date.
-
Knuth Knuth 1.4.1 Subroutines
How to package code as a subroutine in MIX: linkage, passing parameters, returning, and the trade-offs between in-line code and calls. MIX has no stack or call instruction in the modern sense, so you see the mechanics explicitly.
Time About 5 hours this week
Why it matters
Calling conventions are still the glue of every compiled program. Seeing them built by hand makes stack frames, return addresses and ABIs make sense, and connects back to the call frames you built in clox.
Before you start
- 1.3.2 The MIX Assembly Language
How to approach it
Write a MIX subroutine and call it from two places. Then compare the linkage mechanism to how clox pushes CallFrames.
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
- Self-modifying return jumps are normal in MIX. Do not let that surprise you; it is a product of the era.
-
Knuth Knuth 1.4.2 Coroutines
Coroutines: routines that call each other as equals, each resuming where it left off. Knuth shows a pipeline example where one coroutine produces characters and another consumes and transforms them.
Time About 4 hours this week
Why it matters
Generators, async/await, Go's goroutines and Lua coroutines all descend from this idea. Seeing it in assembly makes the "where does my state live" question concrete.
Before you start
- 1.4.1 Subroutines
How to approach it
Trace the example with two columns on paper, one per coroutine, marking where control jumps. Then rewrite the example with Python generators or JavaScript generators and see how much simpler it gets.
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
- Thinking coroutines need threads. They do not; they are just saved resume points.
-
NeetCode LeetCode: 2 NeetCode 150 problems
Two problems from the NeetCode 150, in order. One box for the pair.