Skip to content
LSLab

How Does a Program Counter Select the Next Instruction?

  • Starter
  • Article
  • Ages 10+
  • 6 min read
A microcontroller board under a microscope, with a test probe touching the edge of the chip.

A program counter is a register inside the processor that holds the address of the next instruction to run. The processor fetches the instruction at that address, then moves the address on to the instruction after it. Control instructions such as branches, jumps and function calls can redirect the counter to another address.

Contents
The program counter sits inside the processor and points at exactly one instruction slot in memory.
  • Memory holding the instructions (five stacked slots)
  • Program counter (box with a round dot)
  • Arrow carrying the address of the next instruction
  • Instruction about to run (filled slot)
  • Processor boundary (dashed)

What you will learn

  • Say what the program counter holds and where it sits.
  • Retell the steps a processor takes to fetch one instruction and move on to the next.
  • Explain why the counter sometimes goes up by more than one and sometimes jumps far.

Before you start

You only need to know that a program is a list of instructions and that a register is a small storage cell inside the processor. Everything else is explained as it comes up.

What is a program counter and what does it hold?

The program counter holds an address, not the instruction itself. It is a special register that holds the memory address of the next instruction to be executed, that is, the address of the next machine instruction.

Where do the instructions live? The computer's memory (RAM) contains all the machine instructions of the program. The counter is a finger resting on one line of that list. The list is in memory; the finger is inside the processor.

How does the processor use it to fetch an instruction?

The processor hands the address in the counter to memory, and memory sends back the instruction stored there: the control unit sends this address to main memory, and memory returns the instruction. The instruction that comes back is placed in another register, usually called the instruction register, where it is decoded in the next step.

In the sequential processing model explained here, the counter then moves on. That is three jobs in a row: fetch the memory location the counter addresses into the instruction register, increment the counter to point to the next instruction, and execute the contents of the instruction register. The order matters: the counter goes up right after the fetch, before the instruction is executed. So by the time one instruction finishes, the address of the next is already waiting.

The counter points to an instruction, the instruction goes into the instruction register, then the counter is increased to point to the next one.
  • Program counter (box with a round dot)
  • Memory; the filled slot is the instruction pointed to
  • Instruction register (wide box with a filled bar)
  • Step that increases the counter (circle with a plus sign)
  • Arrows carrying the address and the instruction

Each trip around this model’s loop executes exactly one machine instruction; this is an instruction execution cycle, not a clock tick. When it finishes, the cycle begins again: the processor fetches the next instruction, decodes it and executes it.

How far does the counter move after each instruction?

For sequential execution, the counter moves by the length of the instruction it just fetched. When instructions are stored one after another, adding the length of one instruction to the counter points to the next instruction.

With a fixed 32-bit instruction size, which is four bytes, the counter goes up by four after each instruction. On a teaching processor called Hawk, a halfword instruction takes two bytes, so the counter goes up by two.

That is why "add one" is only right on machines where each instruction fills exactly one unit of memory. Many computers have instructions smaller or larger than one addressable unit of memory, so the counter does not always go up by one.

The counter's step equals the length of the instruction just fetched: equal-length instructions give equal steps, mixed lengths give different steps.
  • Row of equal-length instructions
  • Row of instructions of different lengths
  • Arcs: the counter's steps

When does the counter jump somewhere else?

The counter jumps when a control instruction tells it to. Instructions such as branches, jumps and function calls may change the counter to point to a different location. For a branch or jump, the counter is given a new address and the flow of execution changes direction.

In this model, if the address is not redirected, the processor keeps fetching consecutive instructions. When a branch is taken, a block can be skipped or the program can return to an earlier location. Fetch still uses the address held in the counter.

A taken branch gives the counter a new address and skips the intervening instructions; a branch not taken continues in sequence.
  • Instructions run one after another
  • Skipped instructions (dashed)
  • Large arc: the jump made by a branch instruction
  • Instruction chosen to run next (filled slot)

Real-world example

Picture someone cooking from a printed recipe, one finger on the line being done. When that line is finished, the finger slides down to the next. One line reads "if the water boils, go to step seven": the finger jumps straight to step seven and skips the lines between. The finger is the program counter, the lines are instructions and the sheet is memory. This is only an illustration. A real processor works with circuits and addresses, and has no finger.

Common misunderstandings

The program counter counts how many instructions have run. It holds the address of the instruction about to run. The address grows with instruction length, so it is not a tally of instructions.

The counter holds the instruction itself. Instructions sit in memory. Once fetched, an instruction goes into the instruction register, while the counter keeps only an address.

A program always runs from top to bottom. Branches, jumps and function calls write a new address into the counter, so the order of execution can differ from the order of instructions in memory.

Frequently asked questions

How is the program counter different from the instruction register?

The program counter holds the address of the next instruction. The instruction register holds the instruction that was just fetched and is waiting to be decoded.

Does the counter increase before or after the instruction runs?

It increases right after the instruction is fetched, which is before the instruction is executed. The next trip around the loop then fetches from the new address.

Is the program counter in RAM or in the processor?

It is in the processor, as a register. RAM holds the instructions that the counter points to.

Summary

  • The program counter holds an address; the instruction register holds the fetched instruction.
  • In sequential execution, the counter advances by instruction length in the model considered.
  • Taken branches, jumps and calls can redirect it to another address.

Terms in this article

English and Vietnamese terms, with the meanings used here. Hover, tap or Tab to a term with a dotted underline for an explanation as you read.

program counterbộ đếm chương trình
A register in the processor that holds the address of the next instruction to be executed.
instruction registerthanh ghi lệnh
The register that receives an instruction just fetched from memory so it can be decoded in the next step.
branchrẽ nhánh
A control instruction that can set the program counter to a new address, changing the flow of execution.
main memorybộ nhớ chính
The memory outside the processor that holds a program's instructions and returns one when given its address.

This article is not marked as viewed

Spotted something wrong or unsafe?

Tell the administrator by email. The message already has the article title and address.

Report this article
  • Macro view of a metal-pinned chip on a teal circuit board with small components behind it.
    Starter

    What Is a Microchip?

    Understand microchips, transistors and chip packages through a phone example, and distinguish a semiconductor material from a finished circuit.

    5 min read
  • An opened chip package revealing a silicon die and fine gold bond wires inside ceramic housing.
    Starter

    What Is Inside a Microchip?

    Explore the semiconductor base, transistors and chip package, and see how these parts form a component used in electronic devices.

    5 min read
  • An oscilloscope showing a high-low rectangular pulse beside a digital circuit board.
    Starter

    How Do Voltage Levels Represent Digital Signals?

    See how chips read HIGH and LOW from voltage, how logic families set thresholds, and how a transistor switch flips a level.

    5 min read
  • An exposed memory chip die with fine circuit regions and a row of gold wire-bond contacts on a board.
    Starter

    How Do Bits, Bytes and Machine Words Differ?

    Compare bits, nibbles, bytes and machine words by length, and understand why a byte has a fixed size while word length depends on the design.

    5 min read
See all articles of the topic

Sources

These sources are written for older readers. If they feel hard, read them with an adult.