Menu

Parts of the CPU

The Fetch Decode Execute Cycle

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.

What happens at each stage

StageWhat happens
FetchThe 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.
DecodeThe Control Unit decodes the instruction: it works out what the instruction means and which action is needed.
ExecuteThe 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 fetch-decode-execute cycle as three stages in order, with what happens in each: fetch using the Program Counter, decode by the Control Unit, execute using the ALU and Accumulator. An arrow returns from execute to fetch, and a note says a jump overwrites the Program Counter.

Why the order matters

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.

Following one instruction

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.

Practise this