MIX is a hypothetical computer used in Donald Knuth’s monograph, The Art of Computer Programming (TAOCP). MIX’s model number is 1009, which was derived by combining the model numbers and names of several contemporaneous, commercial machines deemed significant by the author. (“MIX” also has the value 1009 in Roman numerals.)
The 1960s-era MIX has since been superseded by a new (also hypothetical) computer architecture, MMIX, to be incorporated in forthcoming editions of TAOCP. Software implementations for both the MIX and MMIX architectures have been developed by Knuth and made freely available (named “MIXware” and “MMIXware,” respectively).
Several derivatives of Knuth’s MIX/MMIX emulators also exist. GNU MDK is one such software package; it is free and runs on a wide variety of platforms.
Their purpose for education is quite similar to John L. Hennessy's and David A. Patterson's DLX architecture, from Computer Architecture: A Quantitative Approach.
A word has the range −1,073,741,823 to 1,073,741,823 (inclusive) in binary mode, and −9,999,999,999 to 9,999,999,999 (inclusive) in decimal mode. The sign-and-magnitude representation of integers in the MIX architecture distinguishes between “−0” and “+0.” This contrasts with modern computers, whose two’s-complement representation of integer quantities includes a single representation for zero, but whose range for a given number of bits includes one more negative integer than the number of representable positive integers.
A byte is assumed to be at least 6 bits. Most instructions can specify which of the "fields" (bytes) of a register are to be altered, using a suffix of the form (first:last). The zeroth field is the one-bit sign.
MIX also records whether the previous operation overflowed, and has a one-trit comparison indicator (less than, equal to, or greater than). In the diagram below, each register is shown divided into its fields.
|
|
|
|
|
|
|
|
|
|
|
MIX programs frequently use self-modifying code, in particular to return from a subroutine, as MIX lacks an automatic subroutine return stack. Self-modifying code is facilitated by the modification byte, allowing the program to store data to, for example, the address part of the target instruction, leaving the rest of the instruction unmodified.
MIX programs are typically constructed using the MIXAL assembly language; for an example, see the list hello world programs page.
| LDA ADDR,i(0:5) | rA := memory[ADDR + rIi]; |
|---|---|
| LDX ADDR,i(0:5) | rX := memory[ADDR + rIi]; |
| LD? ADDR,i(0:5) | rI? := memory[ADDR + rIi]; |
| LDAN ADDR,i(0:5) | rA := - memory[ADDR + rIi]; |
| LDXN ADDR,i(0:5) | rX := - memory[ADDR + rIi]; |
| LD?N ADDR,i(0:5) | rI? := - memory[ADDR + rIi]; |
| STA ADDR,i(0:5) | memory[ADDR + rIi] := rA; |
| STX ADDR,i(0:5) | memory[ADDR + rIi] := rX; |
| ST? ADDR,i(0:5) | memory[ADDR + rIi] := rI?; |
| STJ ADDR,i(0:5) | memory[ADDR + rIi] := rJ; |
| STZ ADDR,i(0:5) | memory[ADDR + rIi] := 0; |
| ADD ADDR,i(0:5) | rA := rA + memory[ADDR + rIi]; |
| SUB ADDR,i(0:5) | rA := rA - memory[ADDR + rIi]; |
| MUL ADDR,i(0:5) | (rA,rX) := rA * memory[ADDR + rIi]; |
| DIV ADDR,i(0:5) | rA := int((rA,rX) / memory[ADDR + rIi] ); rX := (rA,rX) % memory[ADDR + rIi]; |
| ENTA ADDR,i | rA := ADDR + rIi; |
| ENTX ADDR,i | rX := ADDR + rIi; |
| ENT? ADDR,i | rI? := ADDR + rIi; |
| ENNA ADDR,i | rA := - ADDR - rIi; |
| ENNX ADDR,i | rX := - ADDR - rIi; |
| ENN? ADDR,i | rI? := - ADDR - rIi; |
| INCA ADDR,i | rA := rA + ADDR + rIi; |
| INCX ADDR,i | rX := rX + ADDR + rIi; |
| INC? ADDR,i | rI? := ADDR + rIi; |
| DECA ADDR,i | rA := rA - ADDR - rIi; |
| DECX ADDR,i | rX := rX -ADDR - rIi; |
| DEC? ADDR,i | rI? := rI? - ADDR - rIi; |
| CMPA ADDR,i(0:5) | compare rA with memory[ADDR + rIi]; |
| CMPX ADDR,i(0:5) | compare rX with memory[ADDR + rIi]; |
| CMP? ADDR,i(0:5) | compare rI? with memory[ADDR + rIi]; |
| JMP ADDR,i | goto ADDR + rIi; |
| JSJ ADDR,i | rJ := address of next instruction; goto ADDR + rIi; |
| JOV ADDR,i | if (overflow) then overflow := false; goto ADDR + rIi; |
| JNOV ADDR,i | if (no overflow) then goto ADDR + rIi; else overflow := false; |
| JL, JE, JG ADDR,i JGE, JNE, JLE ADDR,i | if (less, equal, greater) then goto ADDR + rIi; if (no less, unequal, no greater) then goto ADDR + rIi; |
| JAN/JAZ/JAP ADDR,i JANN/JANZ/JANP ADDR,i | if (rA<0 or rA==0 or rA>0) then goto ADDR + rIi; if (rA>=0 or rA!=0 or rA<=0) then goto ADDR + rIi; |
| JXN/JXZ/JXP ADDR,i JXNN/JXNZ/JXNP ADDR,i | if (rX<0 or rX==0 or rX>0) then goto ADDR + rIi; if (rX>=0 or rX!=0 or rX<=0) then goto ADDR + rIi; |
| J?N/J?Z/J?P ADDR,i J?NN/J?NZ/J?NP ADDR,i | if (rI?<0 or rI?==0 or rI?>0) then goto ADDR + rIi; if (rI?>=0 or rI?!=0 or rI?<=0) then goto ADDR + rIi; |
| MOVE ADDR,i(F) | for (n = 0; n < F; n++, rI1++) memory[ADDR+rIi+n] := memory[rI1]; |
| SLA/SRA ADDR,i SLAX/SRAX ADDR,i SLC/SRC ADDR,i | shift rA to the left/right by ADDR+rIi bytes shift (rA,rX) to the left/right by ADDR+rIi bytes rotate (rA,rX) to the left/right by ADDR+rIi bytes |
| NOP | do nothing; |
| HLT | halt execution; |
| IN ADDR,i(F) | read in one block from input unit F into memory[ADDR + rIi] onwards; |
| OUT ADDR,i(F) | output one block to unit F from memory[ADDR + rIi] onwards; |
| IOC ADDR,i(F) | send control instruction to i/o unit F; |
| JRED ADDR,i(F) | if (i/o unit F is ready) then goto ADDR + rIi; |
| JBUS ADDR,i(F) | if (i/o unit F is busy) then goto ADDR + rIi; |
| NUM | rA := numerical value of characters in (rA,rX); |
| CHAR | (rA,rX) := character codes representing value of rA; |