CPU Architecture & the Fetch-Execute Cycle
Inside every computer, from a phone to a games console, sits the central processing unit, or CPU. Its single job is to process instructions: it takes the instructions that make up a program and carries them out, one after another, to make the machine do useful work.
The CPU does this by repeating the same routine over and over, billions of times every second. That routine is called the fetch-execute cycle. To understand how a processor works, you need to know the parts inside it and the steps of this cycle.
The main parts of the CPU
The Arithmetic Logic Unit, usually shortened to ALU, is where the actual calculations happen. It performs arithmetic such as addition and subtraction, and logic operations such as comparing two values to see which is larger or whether they are equal.
The Control Unit, or CU, is the manager of the processor. It decodes each instruction to work out what needs to happen, then sends out control signals that tell the other parts of the computer what to do and when. In this way it coordinates the flow of data around the CPU.
The cache is a small amount of very fast memory built into, or very close to, the CPU. It keeps copies of the data and instructions the processor uses most often, so the CPU can grab them almost instantly instead of waiting for the slower main memory each time.
Finally, the CPU contains a handful of registers. These are tiny storage locations, each able to hold just one value at a time, but they are the fastest storage in the whole computer. The CPU uses them to hold the exact pieces of data and addresses it is working with at that instant.
The ALU does the calculations, the control unit decodes instructions and coordinates the other parts, the cache stores frequently used data for fast access, and registers hold the single values the CPU is using right now.
Von Neumann architecture
Most computers are built using Von Neumann architecture, named after the mathematician John von Neumann. Its key idea is that both the program instructions and the data they work on are stored together in the same memory, and the CPU fetches and carries out those instructions one at a time, in order.
This design relies on a set of special registers. The Program Counter holds the address of the next instruction the CPU will fetch. The Memory Address Register, or MAR, holds the address of the memory location the CPU wants to use next.
The Memory Data Register, or MDR, holds the actual data or instruction that has just been read from memory, or that is about to be written to it. The Accumulator stores the result of the calculations the ALU has just performed.
A register stores either an address or a piece of data. The Program Counter and the MAR store addresses; the MDR and the Accumulator store data. Knowing which each one holds is the key to register questions.
The fetch-execute cycle
Everything the CPU does is built from three repeating stages: fetch, decode and execute. The processor runs through these stages for every single instruction in a program, then loops straight back to the start for the next one.
In the fetch stage, the Program Counter gives the address of the next instruction. The instruction is copied from memory into the CPU, and the Program Counter is then increased by one so that it points to the following instruction, ready for next time.
In the decode stage, the Control Unit examines the instruction and works out exactly what it means and which parts of the computer will be needed to carry it out.
In the execute stage, the instruction is actually carried out. This might mean the ALU performing a calculation and placing the result in the Accumulator, or data being loaded from or saved to memory. The cycle then begins again with the next fetch.
Because instructions and data share the same memory and travel to the CPU along the same route, the processor deals with them in order, one at a time. Working step by step like this keeps the computer predictable and reliable, even though it means a single processor can only ever be part-way through one instruction at any moment.
The fetch-execute cycle has three stages that repeat continuously: fetch the next instruction, decode it, then execute it. The CPU carries out this cycle for every instruction in a program.
Put together, these ideas explain how a processor turns a stored program into action. The components each have a clear role, the registers each hold either an address or a value, and the fetch-execute cycle ties them together into the steady rhythm that drives the whole computer.