MMIX


MMIX is a 64-bit reduced instruction set computing architecture designed by Donald Knuth, with significant contributions by John L. Hennessy and Richard L. Sites. Knuth has said that "MMIX is a computer intended to illustrate machine-level aspects of programming. In my books The Art of Computer Programming, it replaces MIX, the 1960s-style machine that formerly played such a role… I strove to design MMIX so that its machine language would be simple, elegant, and easy to learn. At the same time I was careful to include all of the complexities needed to achieve high performance in practice, so that MMIX could in principle be built and even perhaps be competitive with some of the fastest general-purpose computers in the marketplace."
The processed is numbered as "2009" with Knuth explaining that this is the arithmetic mean from the numbers of other computer architectures; as well as being "MMIX" in Roman numerals.

Architecture

MMIX is a big-endian 64-bit reduced instruction set computer, with 256 64-bit general-purpose registers, 32 64-bit special-purpose registers, fixed-length 32-bit instructions and a 64-bit virtual address space. The MMIX instruction set comprises 256 opcodes, one of which is reserved for future expansion. MMIX uses IEEE 754 floating-point numbers.

Instructions

All instructions have an associated mnemonic. For example, instruction #20 is associated with ADD. Most instructions have the symbolic form "OP X,Y,Z", where OP specifies the sort of instruction, X specifies the register used to store the result of the instruction and the rest specify the operands of the instruction. Each of these fields is eight bits wide. For example, ADD $0,$1,3 means "Set $0 to the sum of $1 and 3."
Most instructions can take either immediate values or register contents; thus a single instruction mnemonic may correspond to one of two opcodes.
MMIX programs are typically constructed using the MMIXAL assembly language. The below is a simple MMIXAL program, which prints the string "Hello, world!":

LOC #100 % Set the address of the program
% initially to 0x100.
Main GETA $255,string % Put the address of the string
% into register 255.
TRAP 0,Fputs,StdOut % Write the string pointed to by
% register 255 to the standard
% output file.
TRAP 0,Halt,0 % End process.
string BYTE "Hello, world!",#a,0 % String to be printed. #a is
% newline, 0 terminates the
% string.

Registers

There are 256 directly addressable general-purpose architectural registers in an MMIX chip, designated by $0 through $255, and 32 special-purpose architectural registers. The special-purpose registers can be accessed with the GET and PUT instructions.
Two of the special registers, rL and rG, determine which of the general registers are local and which are global. All registers from $0... are local registers, and represent a window into an internal stack of registers. Registers from ... are "marginal registers", they always return 0 if they are used as a source in an operation. Using a marginal register as the destination of an operation will cause the machine to automatically increase rL to include that register. All registers ... $255 are called global registers, and are not part of the register stack.

Local register stack

The local register stack provides each subroutine with its own rL local registers, designated by $0 through. Whenever a subroutine is called, a number of local registers are pushed down the stack. The arguments of the called subroutine are left in the remaining local registers. When a subroutine finishes it pops the previously pushed registers. Because the internal stack can contain only a finite number of registers, it may be necessary to store a part of the stack in memory. This is implemented with the special registers rO and rS which record which part of the local register stack is in memory and which part is still in local physical registers. The register stack provides for fast subroutine linkage.

Special registers

The 32 special physical architectural registers are as follows:
  1. rB, the bootstrap register
  2. : When tripping, rB ← $255 and $255 ← rJ. Thus saving rJ in a general register.
  3. rD, the dividend register
  4. : Unsigned integer divide uses this as the left half of the 128-bit input that is to be divided by the other operand.
  5. rE, the epsilon register
  6. : Used for floating comparisons with respect to epsilon.
  7. rH, the himult register
  8. : Used to store the left half of the 128-bit result of unsigned integer multiplication.
  9. rJ, the return-jump register
  10. : Used to save the address of the next instruction by PUSHes and by POP to return from a PUSH.
  11. rM, the multiplex mask register
  12. : Used by the multiplex instruction.
  13. rR, the remainder register
  14. :Is set to the remainder of integer division.
  15. rBB, the bootstrap register
  16. : When trapping, rBB ← $255 and $255 ← rJ. Thus saving rJ in a general register
  17. rC, the cycle counter
  18. : Incremented every cycle.
  19. rN, the serial number
  20. : A constant identifying this particular MMIX processor.
  21. rO, the register stack offset
  22. : Used to implement the register stack.
  23. rS, the register stack pointer
  24. : Used to implement the register stack.
  25. rI, the interval counter
  26. : Decremented every cycle. Causes an interrupt when zero.
  27. rT, the trap address register
  28. : Used to store the address of the trip vector.
  29. rTT, the dynamic trap address register
  30. : Used to store the address of the trap vector.
  31. rK, the interrupt mask register
  32. : Used to enable and disable specific interrupts.
  33. rQ, the interrupt request register
  34. : Used to record interrupts as they occur.
  35. rU, the usage counter
  36. : Used to keep a count of executed instructions.
  37. rV, the virtual translation register
  38. : Used to translate virtual addresses to physical addresses. Contains the size and number of segments, the root location of the page table and the address space number.
  39. rG, the global threshold register
  40. : All general registers references with a number greater or equal to rG refer to global registers.
  41. rL, the local threshold register
  42. : All general registers references with a number smaller than rL refer to local registers.
  43. rA, the arithmetic status register
  44. : Used to record, enable and disable arithmetic exception like overflow and divide by zero.
  45. rF, the failure location register
  46. : Used to store the address of the instruction that caused a failure.
  47. rP, the prediction register
  48. : Used by conditional swap.
  49. rW, the where-interrupted register
  50. : Used, when tripping, to store the address of the instruction after the one that was interrupted.
  51. rX, the execution register
  52. : Used, when tripping, to store the instruction that was interrupted.
  53. rY, the Y operand
  54. : Used, when tripping, to store the Y operand of the interrupted instruction.
  55. rZ, the Z operand
  56. : Used, when tripping, to store the Z operand of the interrupted instruction.
  57. rWW, the where-interrupted register
  58. : Used, when trapping, to store the address of the instruction after the one that was interrupted.
  59. rXX, the execution register
  60. : Used, when trapping, to store the instruction that was interrupted.
  61. rYY, the Y operand
  62. : Used, when trapping, to store the Y operand of the interrupted instruction.
  63. rZZ, the Z operand
  64. : Used, when trapping, to store the Z operand of the interrupted instruction.
Like programs running on almost all other CPUs,
MMIX programs can be interrupted in several ways.
External hardware, such as timers, are a common source of preemption interrupts.
Many instructions cause an interrupts in certain exceptional cases; such as the memory protection page fault exceptions used to implement virtual memory, and floating point exception handling.
MMIX has 2 kinds of interrupts: "trips" and "traps".
The main difference between "trips" and "traps" is that
traps send control to a "trap handler" program in the operating system, but
trips send control to a "trip handler" program in the user application.
Users can also force any interrupt handler to run with explicit software interrupt instructions TRIP and TRAP, similar to some kinds of trap in other computer systems.
In particular, a system call from a user program to the operating system uses a TRAP instruction.

Hardware implementations

, no known hardware implementations of the MMIX instruction set architecture exist. However, the fpgammix project implements MMIX in Verilog, making it possible to implement using a field-programmable gate array.

Software tools

The MMIX instruction set architecture is supported by a number of software tools for computer architecture research and software development.

Simulators and assembler

The GNU Compiler Collection includes an MMIX back-end for its C/C++ compilers, contributed by Hans-Peter Nilsson and part of the main GCC distribution since late 2001., the MMIX back-end to GCC continues to be actively developed and maintained by volunteers.
The above tools could theoretically be used to compile, build, and bootstrap an entire FreeBSD, Linux, or other similar operating system kernel onto MMIX hardware, were such hardware to exist.