TAOCP Vol 1: Fundamental Algorithms · Week 43

TAOCP 1.3.2 The MIX Assembly Language

Updated

About 8 hours23 exercises, rated 00 to M47

Summary

TAOCP 1.3.2 The MIX Assembly Language: MIXAL, the assembly language for MIX: symbols, local labels, pseudo-operations, and worked programs including finding a maximum and printing a table of primes. Budget about 8 hours; do exercises 2, 4 and 8.

It also shows how Knuth annotates programs with execution counts.

Flashcards 17 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

4 steps
  1. Read §1.3.2 The MIX Assembly Language

    Type in the example programs and run them in the simulator, not just read them.

  2. Work the exercises (8 picked)

    Start with Ex 2, Ex 4, Ex 8; log what you solve below.

  3. 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 23 exercises, rated 00 to M47, and Knuth marks eight of them with the triangle for recommended. Two sets: 1 to 8 are about reading MIXAL, and 9 to 23 are short programming problems. Knuth opens the second set with a list of which exercises practice which techniques (table-driven branches, two-dimensional arrays, buffering, subroutines and so on); use it to choose. Exercises 10, 14, 18 and 22 are graded on this site, along with seven more MIX programs for this section.

Worth your time

  • Exercise 210▶ Recommended

    Why the self-jump at the end of the max subroutine is not an infinite loop.

    Discuss

  • Exercise 425▶ Recommended

    Assemble the primes program by hand into numeric words. Takes less time than you fear and demystifies the assembler.

    Discuss

  • Exercise 824▶ Recommended

    Decode a short mystery program by hand without running it.

    Discuss

  • Exercise 925▶ Recommended

    Validate an instruction word with a table-driven multiway branch instead of a chain of tests.

    Discuss

  • Exercise 1031▶ Recommended

    Find a saddle point in a matrix with two index registers. Graded on this site as the saddle exercise.

    Run it in MIX

    Discuss

  • Exercise 1431▶ Recommended

    Print a table of Easter dates, with integer arithmetic and a sneaky negative remainder. Graded as easter.

    Run it in MIX

    Discuss

  • Exercise 1825

    Generate a Farey series with a two-term recurrence, no gcd needed. Graded as farey.

    Run it in MIX

    Discuss

  • Exercise 2231

    Work out the Josephus elimination order with a table of links. Graded as josephus.

    Run it in MIX

    Discuss

Your log

Sign in to log the exercises you work: number, rating, how far you got.

Your notes

Only you

Sign 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 posts

Questions 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 210No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 425No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 824No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 925No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1031No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1431No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1825No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 2231No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Reference

Why it matters

This is where you go from reading machine instructions to writing real programs. The execution-count annotations are how Knuth turns code into exact running-time formulas.

Before you start
  • 1.3.1 Description of MIX
How to approach it

Type in the example programs and run them in the simulator, not just read them. Then change something (print a different number of primes, find the minimum) and get it working. Add the frequency counts yourself and check them against the simulator's instruction counts.

Common traps
  • Local symbols like 2H, 2F and 2B trip people up; F means the next one forward, B the previous one backward.
  • Simulator syntax can differ slightly from the book; check your simulator's manual for column and format rules.

Spot a mistake? Report it

Back to week 43