How does a CPU work?
What does a CPU do?
The CPU is the part of a computer that runs programs. A program sits in main memory (RAM) as a list of instructions in machine code, each one very simple: load a number, add two numbers, store the result, jump to another instruction. The CPU reads these one at a time and carries them out. This idea, instructions stored in memory and fetched and run in order, is called the stored program concept.
These are the main parts of a CPU, as the AQA GCSE specification lists them:
| Part | What it does |
|---|---|
| Control unit (CU) | Decodes each instruction and sends signals that tell the other parts what to do |
| Arithmetic logic unit (ALU) | Does the maths (add, subtract) and logic (AND, OR, compare) |
| Registers | Tiny, very fast stores inside the CPU that hold the values it is working on right now |
| Clock | Sends a steady pulse. Each tick moves the CPU on one step |
| Buses | Sets of wires that carry addresses, data and control signals between the CPU and memory |
| Cache | Small, fast memory on the chip that keeps copies of data the CPU used recently |
The fetch, decode, execute cycle
The fetch, decode, execute cycle (also called the fetch execute cycle) is the loop at the heart of how a CPU works. It uses a few special registers. GCSE courses usually only need the three stages; A-level courses also name the registers.
- Program counter (PC): the address of the next instruction.
- Memory address register (MAR): the address the CPU is about to read from or write to.
- Memory data register (MDR): the data or instruction just read from memory, or about to be written. AQA calls it the memory buffer register (MBR).
- Current instruction register (CIR): the instruction being decoded and run.
- Accumulator (ACC): a general purpose register that holds the result from the ALU.
- Fetch. The PC's value goes into the MAR. Memory sends back whatever is stored there, along the data bus, into the MDR, and it is then copied to the CIR. The PC goes up by 1, so it points at the next instruction.
- Decode. The control unit splits the instruction into its opcode (what to do, such as ADD) and its operand (what to do it to, such as an address).
- Execute. The CPU carries out the instruction. That might mean reading a value from memory, getting the ALU to add it to the accumulator, storing a result, or changing the PC to jump somewhere else.
- Repeat. The cycle starts again with whatever address the PC now holds.
Worked example: tracing a short program
Here is a four instruction program that adds two numbers, written in the small assembly language used by our CPU Simulator. The numbers on the left are memory addresses. Addresses 4 to 6 hold data, not instructions.
0 LDA 4 ; load the value at address 4 into ACC
1 ADD 5 ; add the value at address 5 to ACC
2 STA 6 ; store ACC at address 6
3 HLT ; stop
4 DAT 12
5 DAT 30
6 DAT 0Follow the first instruction in detail. Fetch: the PC holds 0, so 0 goes into the MAR, "LDA 4" comes back into the MDR and is copied to the CIR, and the PC becomes 1. Decode: the control unit sees LDA, meaning load, with the address 4. Execute: 4 goes into the MAR, the value 12 comes back into the MDR, and it is copied into the accumulator.
| Cycle | PC at fetch | CIR | What execute does | ACC after |
|---|---|---|---|---|
| 1 | 0 | LDA 4 | Reads address 4 and loads 12 | 12 |
| 2 | 1 | ADD 5 | Reads address 5, the ALU adds 30 | 42 |
| 3 | 2 | STA 6 | Writes 42 to address 6 | 42 |
| 4 | 3 | HLT | Stops the program | 42 |
After four cycles, address 6 holds 42. Notice that the ACC doesn't change on cycle 3: storing copies the value out to memory but leaves it in the register too. Type this program into the CPU Simulator and step through it to watch each register and bus light up.
What makes one CPU faster than another?
Exam specifications name three factors: clock speed, the number of cores, and cache size. Each one helps in a different way.
Clock speed
The clock speed is how many cycles the CPU runs each second, measured in gigahertz (GHz). Intel gives the example that a 3.2 GHz CPU runs 3.2 billion cycles per second. At 4 GHz, one cycle lasts 1 ÷ 4,000,000,000 seconds, which is 0.25 nanoseconds. A faster clock means each step happens sooner.
A cycle is not the same as an instruction, though. Intel says some instructions take several cycles while modern designs can finish more than one instruction in a single cycle, which is why it advises comparing clock speeds only within the same brand and generation. A newer CPU with a lower clock speed can beat an older one with a higher clock speed.
Cores
A core is a complete processor with its own control unit, ALU and registers. A CPU with several cores can run several streams of instructions, called threads, at the same time. That only helps if the job can be split up. Say exporting a video takes 24 minutes on one core and splits into equal parts. Shared across 8 cores, the best case is 24 ÷ 8 = 3 minutes. A task that runs on one thread, like much of the logic in many games, gets no faster from extra cores, but does from a faster clock.
Try it: this question gives you two CPUs and a job, and asks which one finishes first.
Pick the better of two CPUs for a job that splits up or one that runs on one thread (ChoiceQuiz), random specs.
Press Mark to have your answer marked in the PC Components course.
Cache
Reading from RAM is slow compared with the CPU's clock, so the CPU keeps copies of recently used data in cache, which sits on the chip. Cache comes in levels: L1 is the smallest and fastest, then L2, then a larger L3 that is often shared between cores. Finding data in cache is a hit; going out to RAM is a miss.
To see why it matters, take some example timings: a cache hit takes 1 nanosecond and a RAM read takes 80. A 4 GHz core waiting 80 nanoseconds sits idle for 320 cycles. If 95% of reads are hits, the average read takes 0.95 × 1 + 0.05 × 80 = 4.95 nanoseconds, about 16 times faster than going to RAM every time. A bigger cache means more hits.
What is inside the chip?
Under the parts above, a CPU is made of transistors: microscopic electronic switches that are either on or off. Groups of transistors form logic gates such as AND, OR and NOT, and gates combine into circuits that add binary numbers, compare values and store bits. Apple says its M4 chip, announced in May 2024, holds 28 billion transistors. You can build gates into an adder yourself in the Circuits course.
Von Neumann architecture
Most computers follow the von Neumann architecture: instructions and data share the same memory and the same buses. The Harvard architecture keeps instructions and data in separate memories, so the CPU can fetch both at once. The AQA A-level specification notes that Harvard processors are used a lot in embedded systems such as digital signal processors, while von Neumann is used in general purpose computers.
Common mistakes
- Saying the PC holds the current instruction. The PC points to the next instruction: it stores where that instruction is in memory, not the instruction itself. The CIR holds the current one.
- Forgetting the PC goes up during fetch. It increases as soon as the instruction is fetched, not after it runs.
- Mixing up the MAR and MDR. The MAR holds an address. The MDR holds the data or instruction at that address.
- Saying more cores always means faster. Only work that can be split into threads speeds up.
- Comparing GHz across generations. A newer design does more per cycle, so clock speed alone doesn't decide it.
- Calling cache the same as RAM. Cache is smaller, faster and on the CPU chip itself.
Common questions
What is the difference between a CPU and a GPU?
Is a higher GHz always faster?
What does the program counter do?
What is the difference between RAM and cache?
What language does a CPU understand?
Revision cards
Read the front, say your answer, then flip to check.
Where to go next
- Solve it
CPU Simulator
Step through fetch, decode and execute in assembly
Open the tool - Learn it
PC Components
CPUs, GPUs and RAM: understand what makes a computer tick
Start the course - Test it
GCSE Computer Science
A new exam-style paper every day, with instant marking and a mark scheme
Start today's paper