The program counter
The register that points at the next instruction
The program counter (PC) is a register that holds the memory address of the next instruction to fetch; it increments by one each instruction so the CPU walks through memory in order, and it can be loaded with a new address so a jump can redirect execution.
You built the hardware in the counter lesson, where the program counter is a synchronous up-counter with a load path. This page focuses on its role inside the running machine: it is the CPU's bookmark, the one register that answers "where am I in the program?".
A program is a list of instructions sitting in memory at consecutive addresses. To run them in order, the CPU must remember which address it is up to. That is the entire job of the program counter (PC): an 8-bit register holding the address of the next instruction to fetch.
Two operations, and only two
The PC supports exactly two things, chosen by a control line each cycle:
- Increment (
PC = PC + 1): the normal case. After fetching the instruction at the current address, step to the next one. This is what makes the CPU run straight-line code in order. - Load (
PC = target): a jump. Instead of+1, write a new address into the PC so execution continues somewhere else. This is how loops, branches, and function calls work.
Because both write into the register's data input, a single control line picks count versus load, which is a multiplexer in front of the register's
D. Our small teaching CPU uses only increment (its instruction set has no jump), but the load path is what a fuller machine needs for control flow.PC8): a register that adds 1 to itself each clock. RST clears it to address 0; Q0-Q7 are the current instruction address. Before the first clock the outputs read Z; open it in the lab, pulse reset, then run the clock and watch the address climb 0, 1, 2, 3.Common mistakes. The PC holds an address, not the instruction itself (that is the instruction register's job). The PC is incremented during fetch, so by the time an instruction executes the PC already points at the *next* one, which is why a jump loads an absolute target rather than nudging the current value. And the PC must be reset to a known start address (usually 0) at power-up, or the CPU begins executing garbage.
Try it
What two operations must a program counter support, and which one does a jump use?
Answer
Build it in the lab ↗Increment (
PC = PC + 1), to advance to the next instruction in order, and load (PC = target), to set an arbitrary next address. A jump uses load: it writes the target address into the PC so the next fetch happens there instead of at the following instruction.Frequently asked
What is a program counter?
A program counter (PC) is a register that holds the address of the next instruction to fetch. It increments each cycle so the CPU runs instructions in order, and it can be loaded with a new address to jump.
What two operations does a program counter support?
Increment (
PC + 1) to advance to the next instruction, and load to set a new address for a jump. A control line selects which one happens each cycle, effectively a multiplexer in front of the register input.What is the difference between a program counter and an instruction register?
The program counter holds *where* the next instruction is (an address) and increments each cycle. The instruction register holds *what* the current instruction is (the byte fetched from that address) so the control unit can decode it.
The program counter is the first register touched every cycle: the fetch phase reads the instruction at its address, then bumps it. Next, follow that fetch step by step.
Every lesson here builds toward one thing: a working CPU, from the transistor up.
Open the free lab →Builds towardFetch