ProgramCounter

Inputs

PinTypeDescription
ClockbitOn rising edge (0→1), the PC updates its value
ResetbitReset counter to 0 — highest priority
LoadbitLoad Addr into counter — medium priority
Addrbus8Jump target address (used when Load = 1)
Incbus8Increment amount (defaults to 1 if unconnected)

Outputs

PinTypeDescription
Qbus8Current program counter value (0–255)

How It Works

Picture a teacher's pointer on a line of a textbook exercise: until it moves, the class keeps reading the same line. The program counter PC is the processor's pointer: it holds the address of the byte in ROM that will be executed next. It is the PC that turns a heap of bytes into a program with an order of execution.

On every rising Clock edge one of three actions fires, by seniority: Reset = 1 — clear to 0; Load = 1 — load the Addr address (this is how JMP, JZ and JN work); otherwise Q grows by Inc, or by 1 if Inc is unconnected. Example: a program starting at address 0 walks 0 → 1 → 2 → 3, meets JMP 20 — and the next tick gives Q = 20.

The nuance of level 19: an instruction occupies two bytes — the opcode and the operand. With the default step the processor would fall into the middle of an instruction, so Inc is wired to the constant 2: the PC skips over the operand byte. And at the memory border 255 + 1 = 0 — the count wraps around.

Examples (clock sequence)

SituationResetLoadAddrQ after the edge
Program restart10—0
Normal execution (Inc = 1)00—Q + 1 (for example, 3 → 4)
JMP 20012020
PC+2 step, level 19 (Inc = 2)00—Q + 2 (for example, 4 → 6)

The first row outranks the rest: Reset overrides both the load and the increment.

Usage

The PC is built in level 14 and from level 16 lives inside every processor of the course (levels 16–29). The classic wiring: Q goes to the ROM address input, the instruction operand goes to Addr, and the Decoder signals JumpUncond and JumpCond drive Load through the flags.

A concrete use is every loop and branch: JZ and JN with a backward address turn repetition into a loop, a JMP to the start of the game loop keeps the program from running off into empty memory, and Reset restarts Snake from a clean slate.

Build it yourself →

Related components

Related articles

Frequently Asked Questions

What does the program counter do?

It holds the address of the current instruction and increments every tick — the processor runs the program in order.

What is the +Inc input for?

So jump instructions can move the address several positions at once.

What happens at address 255?

The next edge gives 255 + 1 = 0: the counter wraps around, and the processor keeps reading the program from the start of memory.

Why is the step two in level 19?

Because an instruction takes two bytes: the opcode and the operand. A step of 2 moves the PC straight to the beginning of the next instruction.