A real 8-bit computer laid out as a town: fetch, decode, execute, again and again
Byte Town is a small factory town that runs a real 8-bit toy computer. The RAM Warehouse is a street of 16 numbered lockers, addresses 0 to 15, each holding one byte. The Storage Depot (the disk) holds the saved program, and Power On sends it up the slow road into the lockers. In the middle is the CPU Workshop, a ring road with four stops. At the Program Counter Gate the truck reads the address of the next instruction. It fetches that byte from its locker and brings it to the Fetch Dock. The Decoder Desk splits the byte into an opcode and an operand and lights the road to take next. The ALU Forge does the arithmetic.
Each lap of the ring is one instruction cycle. The eight blocks on the truck's flatbed are the real bits of the byte it is carrying. A raised amber block is a 1. The lamps on the lockers, the gantry, the decoder board and the forge show the machine's real memory, program counter, instruction register, Register A and Zero flag.
Genuinely computed, live, in your browser: every value on screen. The
machine in js/model.js really keeps 16 bytes of memory, a 4-bit program counter,
an 8-bit instruction register, Register A and a Zero flag. Fetch copies memory[PC]
into the instruction register and adds 1 to the PC. Decode is a real shift and mask that splits
the byte into a 4-bit opcode and a 4-bit operand. Execute does what the opcode says: LOAD, ADD,
SUB, STORE, JUMP, JZ (jump if zero), OUT and HALT. ADD and SUB are real 8-bit arithmetic that
wraps at 256 and set the Zero flag. JZ really reads that flag. When you flip a bit or type a
value, the change goes into the same memory the machine runs from, so what happens next comes
from your edit. Nothing is pre-recorded. The "if it runs to the end" prediction runs a copy of
the machine forward.
Scaled down: 16 bytes of memory instead of the roughly 16 billion in a laptop. One 8-bit working register instead of 16 or more 64-bit ones. 8 instructions instead of hundreds or thousands. A 4-bit address space, so the PC wraps from 15 to 0. And one instruction every few seconds, where a real core manages a few billion cycles per second, often running several instructions per cycle.
Assumed (design choices of this machine): the instruction set and its encoding belong to this town. It is modelled on teaching computers such as the SAP-1 and is not a commercial processor. Only ADD and SUB set the Zero flag. Opcodes 8–15 are undefined and are treated as HALT. There is no carry or negative flag, so a subtraction below 0 simply wraps to 255.
Deliberately faked: distance and time. In the town, memory looks a short drive away and the disk a long one. The real gaps are far larger than any road here can show: RAM answers in about 100 ns, an SSD in about 100 µs and a hard disk in about 10 ms. Booting is also simplified: the whole 16-byte image is copied to addresses 0–15 in one go, with no boot loader or operating system. The truck loads an operand at the locker before it reaches the forge. In a real CPU the read and the arithmetic happen inside a single execute step, and the truck simply shows the value in transit. Real processors also overlap the stages: they fetch the next instruction while one is still executing, and caches keep most memory trips short. This town does one stage at a time so you can watch each one. Finally, the run stops after 99 cycles so that an endless loop you write does not run forever. A real machine would keep going. Treat the roads and travel times as scenery. The bits, registers and memory are the lesson.
The first time the truck reaches a station it stops long enough for you to read that station's write-up, between 9 and 26 seconds, and a bar under the text shows how much of the stop is left. Later laps of the ring are the same road with a different byte, so the truck drives faster. Once every station has been explained, the whole town speeds up. Space holds any stop for as long as you like. S moves one station. C runs one whole fetch–decode–execute cycle and stops at the PC Gate. The Speed slider scales everything, reading stops included. Power On reloads the program from disk and keeps track of what you have already read. ⟲ replays the slow tour.
Built from the isometric-explainer skill. All code and copy written for this module.