Parts of the CPU
The fetch-decode-execute cycle is the set of steps the Central Processing Unit (CPU) works through to run each instruction of a program. The three stages always happen in the same order: fetch, then decode, then execute. The CPU finishes one instruction and then starts again for the next.
| Stage | What happens |
|---|---|
| Fetch | The CPU fetches the next instruction from memory, using the address stored in the Program Counter. The Program Counter is then increased, so it points at the instruction that comes after it. |
| Decode | The Control Unit decodes the instruction: it works out what the instruction means and which action is needed. |
| Execute | The instruction is carried out. The Arithmetic Logic Unit (ALU) may carry out a calculation, and its result is placed in the Accumulator; data may be read from or written to memory; or a jump may overwrite the Program Counter. |
The CPU cannot execute an instruction it has not fetched, and it cannot act on an instruction until the Control Unit has decoded it. Running the stages as fetch, execute, decode would mean trying to carry out something the CPU has not yet understood, so that order is always wrong.
When execute finishes, the cycle begins again and the next instruction is fetched. Because the Program Counter was increased after the fetch, the CPU moves on one instruction at a time. A jump is the exception: it changes the Program Counter, which is how programs repeat or skip sections of code.
Picture a program that makes a warning light flash in a factory. One instruction is a jump back to an earlier address, so the flashing repeats. Before fetch, the Program Counter holds the address of that jump instruction. In fetch, the CPU copies the instruction from memory and the Program Counter moves on. In decode, the Control Unit works out that it is a jump and finds the address to go to. In execute, that address is placed into the Program Counter, so the next fetch starts from the earlier instruction and the light keeps flashing.
OCR GCSE Computer Science · Parts of the CPU