Free tool · TAOCP §1.3
MIX emulator and MIXAL assembler, in your browser
Write MIXAL, assemble it and run it on MIX, the imaginary computer from Knuth's The Art of Computer Programming, right here. No install. 14 exercises from §1.3 are graded on the server when you submit them, and a pass verifies that week of the path.
What MIX is
A made-up 1960s-style machine: words of five bytes and a sign, registers A and X, six index registers, a jump register, and 4000 words of memory. Every program in TAOCP Volumes 1 to 3 is written for it, which is what lets Knuth count running time exactly. More on MIX.
How to use it
- Type or paste MIXAL into the editor below.
- Assemble and run it; step through to watch the registers and memory.
- Pick an exercise from the list to load its starting code and tests; sign in to submit it for credit.
A first program
ORIG 100
START ENTA 0
ENT1 10
LOOP INCA 0,1
DEC1 1
J1P LOOP
HLT
END STARTAdds 1 to 10; register A ends at 55.
Scratchpad
Graded exercises
Each one loads its starting code and test cases into the emulator. Check runs them in your browser; sign in to submit for credit.
- Hello, printer §1.3.2
Print one fixed line on the line printer and halt. Verifies Knuth 1.3.2. - Sum of a table §1.3.2
Add up n signed numbers stored in memory. Verifies Knuth 1.3.2. - Find the maximum §1.3.2 (Program M)
A subroutine that returns the largest of n numbers and where it is. Verifies Knuth 1.3.2. - Euclid's algorithm §1.1, §1.3.2
Compute the greatest common divisor of two positive numbers. Verifies Knuth 1.3.2. - Factorial §1.3.2
Compute n! for small n. Verifies Knuth 1.3.2. - Reverse a table in place §1.3.2
Reverse the order of n words in memory without a second table. Verifies Knuth 1.3.2. - Read a number from a card §1.3.1 (NUM)
Convert ten decimal digits on a punched card to a binary number. Verifies Knuth 1.3.1. - Print a number §1.3.1 (CHAR)
Print the value in rA as ten decimal digits. Verifies Knuth 1.3.1. - Copy cards to the printer §1.3.1 (I/O)
Read k cards and print each one as a line. Verifies Knuth 1.3.1. - Table of primes §1.3.2 (Program P)
Compute the first 500 primes and print them as a 50-line table. Verifies Knuth 1.3.2. - Saddle point §1.3.2
Find an entry that is the smallest in its row and the largest in its column. Verifies Knuth 1.3.2. - Date of Easter §1.3.2
Print the date of Easter Sunday for a range of years. Verifies Knuth 1.3.2. - Farey series §1.3.2
A subroutine that generates the Farey series of order n with a two-term recurrence. Verifies Knuth 1.3.2. - The Josephus problem §1.3.2
Work out the order in which every m-th man in a circle of n is eliminated. Verifies Knuth 1.3.2.
Questions
Is this the same MIX as in TAOCP?
Yes: the MIX of Volume 1, §1.3.1, with the MIXAL assembly language of §1.3.2. It is meant for working the book's examples and exercises.
Can I run MIX programs offline?
GNU MDK is the classic desktop MIX toolkit. This page needs no install and grades exercises.
Is MIX the same as MMIX?
No. MMIX is Knuth's later 64-bit RISC machine used from Volume 4A on. This emulator runs MIX.
Learn more: what MIX is, MIXAL, the §1.3.1 reading guide, how to read TAOCP and Volume 1.