ProgramCounter
Inputs
| Pin | Type | Description |
|---|---|---|
| Clock | bit | On rising edge (0→1), the PC updates its value |
| Reset | bit | Reset counter to 0 — highest priority |
| Load | bit | Load Addr into counter — medium priority |
| Addr | bus8 | Jump target address (used when Load = 1) |
| Inc | bus8 | Increment amount (defaults to 1 if unconnected) |
Outputs
| Pin | Type | Description |
|---|---|---|
| Q | bus8 | Current program counter value (0–255) |
How It Works
The ProgramCounter (PC) tracks the address of the next instruction to execute. On each clock rising edge, it evaluates its inputs in the following priority order:
- Reset = 1 → Q = 0 (highest priority — aborts jump and increment)
- Load = 1 and Reset = 0 → Q = Addr (jump to target address)
- Neither Reset nor Load → Q = Q + Inc (normal sequential execution)
Important: the Inc pin has a special default behavior. If nothing is connected to Inc, the PC checks this with isInputConnected and defaults Inc to 1. This means:
- Inc unconnected → PC increments by 1 each cycle (standard behavior).
- Inc connected to a constant or signal → PC increments by that value.
The Q output always reflects the current address and connects to the ROM's address input.
Usage
The ProgramCounter is the heart of program flow control:
- Level 16: CPU — connects to ROM, drives instruction fetch.
- Levels 18–29: all subsequent levels use the PC for program execution.
Typical connections:
- Clock: connect from the Clock element's Q output.
- Inc: leave unconnected for +1 stepping, or connect to a constant bus for variable increments.
- Load/Addr: driven by JMP (JumpUncond) and JZ (JumpCond) signals from the Decoder — the Addr comes from the instruction operand.
- Reset: optionally connected to a reset button or logic for program restart.
- Q: connects to the ROM address input and optionally to a Display or LED8 for monitoring.