SearchA-ZM › MIX

MIX

2026 Open source · Public domain Online

An authored, in-browser MIX computer - the mythical machine of Donald Knuth's "The Art of Computer Programming". A word is a sign plus five 6-bit bytes; it has registers rA, rX, rI1..rI6 and rJ, 4000 words of memory, an overflow toggle and a three-way comparison indicator. It boots summing 1..10 and printing a greeting, then reads a line with IN, and plugs into the shared debugger, so you can single-step one instruction, set breakpoints on a memory address, watch a word, and feed the card reader from an on-screen keyboard.

Visit the official site ↗

Runs on: Web browser

MIX Online Emulator

Play MIX using JavaScript directly in your browser.

Configurations

ConfigurationEmulatorMachineOSLegal
Sum and print demoMIXopenOpen ⛶

Notes

Embedding

The MIX computer here is authored from scratch in one small file, mix.js. It is a plain global - MIX.create(canvas) returns a machine object whose whole state is ordinary JavaScript, so the debugger reaches straight into it with no wasm heap or hidden loop.

Boot. Assemble a program from instruction words (MIX.inst(C,A,I,F)) and text (MIX.text), load it, then run your own loop built on mix.step() (execute exactly one instruction):

var mix = MIX.create(canvas);
mix.load({ start:0, words:{ 0:MIX.inst(49,10,0,2) /* ENT1 10 */ } });
(function loop(){
  var r = mix.step();          // 'ok' | 'halt' | 'input'
  mix.render();
  if (r !== 'halt') requestAnimationFrame(loop);
})();

The machine is plain fields. Everything the debugger needs is live on the object:

MemberKindWhat it does
mix.step()methodFetch, decode and execute one instruction. Returns 'ok', 'halt' or 'input' (blocked on an IN with no line queued).
mix.rA · mix.rX · mix.rI[n] · mix.rJfieldsThe registers, each a sign-magnitude word ({ s, b:[…] }), read and written live.
mix.memfieldThe 4000-word memory (an array of sign-magnitude words).
mix.peek(a) · mix.poke(a,v)methodsSide-effect-free read / write of a word's signed value, used by the debugger's memory views.
mix.feedLine(s)methodQueue a line of text for the next IN instruction (the card reader / terminal).

Because the registers and memory are ordinary JavaScript, breakpoints are a host-side Set of PC values checked before each step(), and watchpoints are checked inside poke - no changes to the core.

Debugger integration

The boot shim publishes window.EMU_BOOT with a full transport: pause / resume / isPaused, stepInsn(n) (one instruction), step(n) (a burst), reset, plus breakpoints (a Set of PC values the loop checks before each step) and watchpoints (a Set of memory addresses, checked inside poke). A CPU decoder - /debugger/src/cpus/mix.js - turns each word back into OP ADDRESS,I(F). It reads the true sign-magnitude word off EMU_BOOT.mix.mem, because the shared views hand decoders a byte-masked reader that cannot express a MIX word.

Architecture

MIX is the machine of "The Art of Computer Programming": a sign-magnitude computer small enough to hand-assemble, rich enough to write real algorithms.

  • Words - a sign (+/-) plus five 6-bit bytes (each 0..63), so a word holds a signed value up to 645-1.
  • Registers - rA and rX are full words; rI1..rI6 are 2-byte index registers; rJ is a 2-byte (always +) jump register.
  • Memory - 4000 words. An overflow toggle and a three-way comparison indicator (LESS / EQUAL / GREATER) hold condition state.

An instruction word is (+/-) AA I F C: a 2-byte signed address AA, an index register I, a field/variant/device byte F and the opcode C. The effective address is M = A + rI[I]; the field F = 8L+R selects bytes L..R of a word. The shared debugger's mix decoder turns each word back into OP ADDRESS,I(F), so you can watch the fetch-decode-execute cycle one instruction at a time.