TAOCP Vol 1: Fundamental Algorithms · Week 31

TAOCP 1.4.1 Subroutines: reading guide

About the book

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.

Links

Back to week 31