Menu

Parts of the CPU

Program Counter

The Program Counter (PC) is a register inside the CPU. It holds the memory address of the next instruction to be fetched. It holds an address only โ€” not the instruction itself, and not the data that the instruction works on.

Memory is a long list of numbered locations. Each address holds either an instruction or a piece of data, so holding one of those addresses tells the CPU exactly where to look.

The table shows a short program in memory. The instructions are written in English so you can follow them; in memory they are stored as binary codes.

Memory addressInstruction stored there
60get the player's answer
61check whether the answer is correct
62increase the score by one
63show the score

During the fetch stage

In the fetch stage the CPU uses the number in the Program Counter to work out where to look. If the Program Counter holds 60, the CPU collects the instruction at address 60, which is "get the player's answer".

Then it is incremented

As soon as the instruction has been collected, the Program Counter is incremented: 1 is added to it, so it now reads 61, where the following instruction is stored. Instructions normally sit one after another in memory, so adding 1 moves to the next one. The next fetch uses 61, then 62, then 63.

The Program Counter is not counting instructions, and it is not counting programs. Adding 1 simply moves it along to the next address, like moving to the next line when reading a list.

A jump changes the address

Programs do not always run straight down the list. If the instruction that has just been executed is a jump, the CPU replaces the value in the Program Counter with a different address during the execute stage. The next instruction is then fetched from there instead. A loop or an if statement relies on jumps to go back to an earlier instruction, or to skip forward past instructions it does not need.

Practise this