TAOCP Vol 1: Fundamental Algorithms · Week 45
TAOCP 1.4.1 Subroutines
Updated
Summary
TAOCP 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. Budget about 5 hours; do exercises 1, 2 and 4.
MIX has no stack or call instruction in the modern sense, so you see the mechanics explicitly.
This week's steps
3 stepsRead §1.4.1 Subroutines
Write a MIX subroutine and call it from two places.
Start with Ex 1, Ex 2, Ex 4; log what you solve below.
Write down one thing you'd explain to someone
A few sentences in your own words in Your notes: the idea, why it works, an example. 30 words ticks this.
Sign in to track this: tick each step off and it counts toward your week.
Exercises
This section has 7 exercises, rated 10 to 26, and Knuth marks three of them with the triangle for recommended. Small set, all worth doing. Write and run 4 and 6.
Worth your time
Exercise 421▶ Recommended
Generalize the max subroutine to a strided range with extra parameters.
Exercise 626▶ Recommended
Write a subroutine that mimics the MOVE instruction, with its parameters stored right after the call.
Your log
Sign in to log the exercises you work: number, rating, how far you got.
Your notes
Only youSign in to keep private notes on this guide, in Markdown. They stay yours: never on your profile, and you can export them all.
Discussion
0 postsQuestions about the reading go here; each exercise has its own thread below. Hints over answers.
No posts yet. Ask a question or share a tip.
Sign in to postAnyone can read. Posting needs an account with a confirmed email.
Exercise threads
One thread per exercise. Open one to ask for a nudge or check your thinking.
Exercise 110No posts yet
Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler:
||like this||or a```spoilerblock.Sign in to postAnyone can read. Posting needs an account with a confirmed email.
Exercise 210No posts yet
Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler:
||like this||or a```spoilerblock.Sign in to postAnyone can read. Posting needs an account with a confirmed email.
Exercise 421No posts yet
Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler:
||like this||or a```spoilerblock.Sign in to postAnyone can read. Posting needs an account with a confirmed email.
Exercise 521No posts yet
Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler:
||like this||or a```spoilerblock.Sign in to postAnyone can read. Posting needs an account with a confirmed email.
Exercise 626No posts yet
Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler:
||like this||or a```spoilerblock.Sign in to postAnyone can read. Posting needs an account with a confirmed email.
Exercise 720No posts yet
Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler:
||like this||or a```spoilerblock.Sign in to postAnyone can read. Posting needs an account with a confirmed email.
Reference
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.
Common traps
- Self-modifying return jumps are normal in MIX. Do not let that surprise you; it is a product of the era.