CPUabtotal51Put 2 in box a2Put 3 in box b3Add a and b → total4Show total1a = 22b = 33total = a + b4print(total)calcgamebrowserOS235
Back row: hardware, the machine you can touch (CPU, memory, screen and keyboard)Front row: software, the instructions (recipe, Python code, other programs)Tokens: an instruction hopping to the CPU, numbers hopping to memory and the screenHardware at the back: the CPU and the memory boxes on a board, and the screen with its keyboard. Software in front: a recipe in plain words, the same four steps in Python, and a shelf of other programs. As each line runs it lights on both cards, its instruction hops to the CPU, and the CPU moves numbers between memory and the screen: 2 into a, 3 into b, 2 + 3 = 5 into total, then 5 onto the screen. Loading a different program makes the same hardware a calculator, a game or a browser. Real CPUs work on several machine instructions at once, and one Python line becomes many tiny machine instructions. The result is the same as doing them one at a time, in order, which is how the figure shows it.

Hardware and software

  1. Hardware is the physical computer: the CPU (the processor) that does the work, the memory that holds what it is working on, and the screen and keyboard. On its own, hardware does nothing at all.

Running the program

Many programs

What happens

;; step 1/9 · hardware
hardware  the parts you can touch
  CPU       central processing unit: carries out instructions
  memory    holds the program and the values it is using
  screen    output: how a program shows you things
  keyboard  input: how you type to a program
with no instructions, none of it does anything

Real CPUs work on several machine instructions at once, and one Python line becomes many tiny machine instructions. The result is the same as doing them one at a time, in order, which is how the figure shows it. The labelled boxes are a simplification. In Python a name such as a refers to an object (here the number 2) kept in memory, and memory itself is numbered by address, not by name.