SearchA-ZZ › Zuse Z3

Zuse Z3

1941 Open source · Public domain Online

The Zuse Z3, built by Konrad Zuse in Berlin and first demonstrated on 12 May 1941, was the world's first programmable, fully automatic digital computer. This is an original implementation, written from scratch for emulators.org. It is built from about 2,600 telephone relays in the real machine, and it computes in 22-bit binary floating point: one sign bit, a 7-bit exponent and a 14-bit mantissa. It has 64 words of relay memory, a two-register arithmetic unit, and a program read from punched film as a stream of 8-bit instructions. Input and output are decimal: a keyboard for the operator and a lamp field for the result.

It boots with the classic demo already running: it computes the hypotenuse of a 3, 4 right triangle, sqrt(3² + 4²) = 5, and lights the answer on the decimal lamp field, looping forever on the punched film. The whole machine, both registers, the film position and every memory cell, is exposed to the shared debugger, so you can single-step the fetch-execute cycle, set a breakpoint on a film position, watch a memory cell for writes, and read the film back as a disassembly. The other configurations wait for the operator keyboard: an on-screen decimal keypad, mapped to the physical number keys, feeds a decimal value that a read instruction consumes.

Runs on: Web browser

Zuse Z3 Online Emulator

Play Zuse Z3 using JavaScript directly in your browser.

Configurations

ConfigurationEmulatorMachineOSLegal
Pythagoras demoZuse Z3Zuse Z3openOpen ⛶
Multiply (keypad)Zuse Z3Zuse Z3openOpen ⛶
Square root (keypad)Zuse Z3Zuse Z3openOpen ⛶

Chips

Notes

Embedding

The Zuse Z3 here is authored from scratch in one small file, z3.js. It is a plain global — ZUSE.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. Create the machine on a <canvas>, load a program (a punched-film byte array plus optional memory constants and queued keyboard input), then run your own loop built on z3.step() (execute exactly one film instruction):

var z3 = ZUSE.create(canvas);
z3.load({ film: [0xC1, 0xC1, 0x48, 0x83, 0xC2, 0xC2, 0x48, 0xC3, 0x60, 0x58, 0x78],
          mem: { 1: 3, 2: 4 } });
(function loop(){
  var r = z3.step();               // 'ok' | 'stop' | 'wait'
  z3.render();
  if (r === 'ok') requestAnimationFrame(loop);
})();

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

MemberKindWhat it does
z3.step()methodExecute exactly one film instruction; returns 'ok', 'stop' (unused opcode / empty film) or 'wait' (a Lu needs keyboard input). The single-step primitive.
z3.r1 · z3.r2fieldsThe two floating-point registers, as JavaScript doubles, read and written live.
z3.pcfieldThe film position (program counter); the film is a physical loop, so it wraps.
z3.memfieldThe 64 relay words (an array of doubles).
z3.peek(a) · z3.poke(a,w)methodsSide-effect-free read / write of a memory cell as a 22-bit floating-point word, used by the debugger's memory views.
z3.encode(x) · z3.decode(w)methodsConvert a double to / from the Z3's 22-bit word (sign + 7-bit exponent + 14-bit mantissa).
z3.keyDigit / keyPoint / keySign / keySubmitmethodsThe operator keyboard: build a decimal number in the input latch and queue it for the next Lu.
z3.onWrite(a,w)hookCalled on every memory write; the boot uses it to implement watchpoints.

Because R1, R2, the film position and the store are ordinary JavaScript, breakpoints are a host-side Set of film positions checked before each step(), and watchpoints are checked inside onWrite — no changes to the core.

Debugger integration

The Z3 has no bytes-and-addresses CPU, so its debugger view is built from two very different memory spaces plus a custom decoder:

  • A new z3 decoder (/debugger/src/cpus/z3.js) disassembles the 8-bit film instruction. The top two bits pick the class (Pr z load, Ps z store, or an 01 sss 000 operation), the middle three bits pick the operation (Lm Li Lw Ls1 Ls2 Lu Ld), and anything else prints as .op. It reads the plain film byte the shared disassembly view hands it — no live-peek trick needed.
  • Two chips. The punched film is decoded with z3 in the disassembly view; the relay memory is 64 words shown as 22-bit codes (hex and bits). Both reads are side-effect-free.
  • Registers. R1 and R2 are surfaced as their live 22-bit floating-point words (via encode), writable back through decode; the film position is the program counter; STOP, WAIT and SEL2 (which register the next load targets) are flags.
  • Transport. The boot loop implements pause / resume / one-instruction step, execution breakpoints on the film position, and write watchpoints wrapped around onWrite — all on EMU_BOOT.transport.

Because the Z3 has no keyboard-mapped CPU input, the operator keyboard is modelled directly: the on-screen keypad and the physical number keys drive keyDigit/keySubmit, which queue a decimal value that the next Lu instruction consumes; a Lu with an empty queue returns 'wait' and the loop parks until you press START.

Architecture

The Zuse Z3, completed by Konrad Zuse in Berlin and first demonstrated on 12 May 1941, was the world's first programmable, fully automatic digital computer. It was built from about 2,600 telephone relays and it computed in binary floating point — decades before that became standard.

  • 22-bit word = 1 sign bit + a 7-bit exponent (two's complement, −64..63) + a 14-bit mantissa (a normalised fraction with an implicit leading 1).
  • 64 words of relay memory (the store), addressed 0–63.
  • Two arithmetic registers, R1 and R2. A load drops its value into R1 then R2 alternately; a two-operand operation computes into R1 and re-arms the loader on R2 so results accumulate; square root is one-operand on R1.
  • Program on punched film — a stream of 8-bit instructions, with no conditional branch; the film was physically a loop for repeated computation.
  • Decimal I/O — a keyboard for input and a lamp field for the decimal result.

The 8-bit instruction (after Raul Rojas's reconstruction) decodes from its top two bits:

BitsMnemonicEffect
11 zzzzzzPr zload memory cell z into the arithmetic unit
10 zzzzzzPs zstore the arithmetic unit to memory cell z
01 001 000LmR1 ← R1 × R2
01 010 000LiR1 ← R1 ÷ R2
01 011 000LwR1 ← √R1
01 100 000Ls1R1 ← R1 + R2
01 101 000Ls2R1 ← R1 − R2
01 110 000Luread a decimal number from the keyboard
01 111 000Lddisplay the result on the lamp field

The shared debugger's z3 decoder turns each film byte back into these mnemonics in the disassembly view, so you can watch the fetch-execute cycle one instruction at a time as the lamps light.