Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 06 · How Computers Work · Build the machine's software · with code: Go · about 19 min to read

Play it as a journeyTutor comes with a plan

Build a stack machine

The CPU
The CPU · Open board

The loop every chip runs: read the next instruction, work out what it wants, do it, go back for the next. This lesson writes that same loop as a few dozen lines of Go, and then makes it run real programs.

Before you start. A chip runs one loop forever: fetch the next instruction, decode which operation it is, execute it, with one number (the program counter) saying where the next instruction sits, and a jump being nothing more than writing a new number there (The CPU (fetch-decode-execute, the ISA, assembly)). A compiler turns the words you write into those instructions, some languages stop halfway at a portable in-between code that a small program reads, and a function call leaves a note saying where to come back to (How Code Becomes Execution (compilers, stack & heap)). You need Go installed to run the code. Reading it needs nothing.

Lesson 31 of 41 in How Computers Work

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 1974-1977: one Pascal for every machine on campus
  • A computer that is only a program: the virtual machine
  • Why a pile and not named boxes: the stack
  • Numbers, not words: bytecode, and the assembler that writes it
  • Deciding and repeating: one jump that looks at the pile
  • Coming back: the return stack

Terms it explains: virtual machine, stack, bytecode, assembler, return stack, ALU, assembly, branch prediction, CISC vs RISC, clock, core, fetch-decode-execute, flags, immediate, IPC, ISA, opcode, operand, out-of-order, PC (program counter), pipelining, register, superscalar.

Related paper

Review How Computers Work