Index

Module 05 · How Computers WorkBuild the machine's software

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.

Continue reading with a plan

The first three lessons of every track are free. This lesson is included with a plan, which unlocks every lesson, board, video, lab and paper for one price.

View plans →Already a member? Sign in

Related paper

Review How Computers Work →

Saved in this browser, and to your account when you sign in.