SSDaddr 0addr 1addr 2addr 3PCIRr1r2CPU1 r v put v in r3 a b add rb to ra0 stopCLKFETCHDECODEEXECUTE11212331200011212331200023235
Back row: the SSD, memory (RAM), the CPU with its registers, and the clockFront row: the instruction set card and the fetch → decode → execute loopTokens: instructions hopping from disk to memory to the CPU, digits, and numbers landing in registersAt the back, on one board: the SSD holding the program file, four memory boxes (addresses 0 to 3), the CPU with its registers (PC, IR, r1, r2) and the clock. In front: the CPU's instruction set and the cycle, fetch, decode, execute. The four numbers are copied from the disk into memory. Then each cycle the instruction at the PC's address hops into the IR, splits into its digits, and is carried out: r1 = 2, r2 = 3, r1 = 2 + 3 = 5, stop. The instruction set here is made up for teaching, with instructions written as decimal digits. Real CPUs use binary codes. On an x86-64 PC, for example, the bytes B8 02 00 00 00 mean "put 2 in register eax" and 01 D8 means "add ebx to eax" (Intel Software Developer’s Manual, Vol. 2).

From disk to memory

  1. A program is a file kept on the disk, here an SSD (solid-state drive). The disk keeps files even when the power is off, but it is slow, so the CPU does not run programs straight from it.

One cycle

Running the rest

What happens

;; step 1/11 · on-disk
disk     stores files, even with the power off
         program file: 4 instructions
memory   (empty: the program is not loaded yet)
CPU      waiting

The instruction set here is made up for teaching, with instructions written as decimal digits. Real CPUs use binary codes. On an x86-64 PC, for example, the bytes B8 02 00 00 00 mean "put 2 in register eax" and 01 D8 means "add ebx to eax" (Intel Software Developer’s Manual, Vol. 2). One instruction does not always take exactly one tick. Modern CPUs overlap several instructions at once (pipelining) and have several cores, so they can finish more than one instruction per tick, or need several ticks for a slow one.