← All lessons
How computers work · Lesson 4 of 7

The processor

The processor, or CPU (central processing unit), is the part that runs programs. It only understands very simple instructions, called machine code: load a number from memory, add two numbers, compare them, store the result, jump to a different instruction. Every program, however complicated, comes down to long lists of these.

It keeps the values it's working on in registers, a handful of tiny, extremely fast storage slots inside the chip. The arithmetic logic unit (ALU) does the sums and comparisons with circuits of logic gates. A special register, the program counter, holds the address of the next instruction.

The CPU runs a loop called the fetch–decode–execute cycle. Fetch: read the instruction at the program counter's address from memory. Decode: work out what it means. Execute: do it, then move the program counter on to the next instruction (or somewhere else, for a jump).

LOAD  R1, [100]   ; R1 = the number at address 100
LOAD  R2, [104]   ; R2 = the number at address 104
ADD   R3, R1, R2  ; R3 = R1 + R2
STORE R3, [108]   ; save R3 at address 108

A clock keeps it in step. A 3 GHz processor's clock ticks 3 billion times a second, and modern CPUs finish several instructions per tick. They also have several cores, each a processor of its own, so they can run several things at once. Languages like Python are translated into these instructions (by a compiler or an interpreter) before the CPU can run them.

Practice

Put the steps of the instruction cycle in order.

  1. Tap the items below in order.
More info

Quick reference

CPURuns programs, one simple instruction at a time (per core).
Machine codeThe CPU's own instructions: load, add, compare, store, jump.
RegisterA tiny, very fast slot inside the CPU.
Program counterWhere the next instruction is.
Fetch–decode–executeThe cycle every instruction goes through.
GHzBillions of clock ticks per second.

The other computer science courses