Skip to content
BetterDL

Program counter (PC)

Also called: instruction pointer, instruction address register

The CPU register that holds the memory address of the next instruction to fetch. It normally adds 1 each fetch; jumps load it.

The program counter answers one question: where is the next instruction? It holds a memory address, and the fetch step reads the word at that address.

The name is a little misleading: it points at an address rather than counting anything. Some architectures, such as x86, call it the instruction pointer instead.

How it changes in Tiny8:

  • During fetch (step F2), PC ← PC + 1. Most instructions are followed by the next word in memory, so the PC moves on straight away, in parallel with the memory read.
  • On a jump, the execute step overwrites it: PC ← IR[3:0]. A conditional branch does this only when its condition holds.
  • At reset, PC = 0, so the program starts at address 0.

So by the time an instruction executes, the PC already points at the next one. A JZ that isn't taken does nothing at all; the PC + 1 from fetch stands.

Its width is set by memory size: it needs one bit per address bit. Tiny8's 16 words need a 4-bit PC.

Worked examples

Example

Following the PC

Tiny8 fetches the word at address 6, which is JMP 2 (52). What does the PC hold after each step?

  1. 1.

    Before F1: PC = 6.

  2. 2.

    F1, MAR ← PC: PC stays 6.

  3. 3.

    F2, MDR ← M[MAR], PC ← PC + 1: PC = 7.

  4. 4.

    F3 and D leave it alone: still 7.

  5. 5.

    E1, PC ← IR[3:0]: PC = 2. The next fetch reads address 2.

Example

Sizing a PC

A machine has 2048 words of memory. How wide must its PC be?

  1. 1.

    2¹¹ = 2048, so 11 address bits.

  2. 2.

    The PC holds an address, so it's 11 bits wide, whatever the word size.

Common mistakes

  • Thinking the PC holds the current instruction. It holds an address; the instruction itself goes into the IR.

  • Adding 1 again after a not-taken branch. The PC was already advanced during fetch.

  • Sizing the PC by the word size. It's sized by the number of addresses.

Practice Program counter (PC)

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Program counter (PC) is taught in Basic CPU / Computer Architecture.