| Mnemonic | Opcode | Bytes | Description |
|---|---|---|---|
| NOP | 0x00 | 1 | No operation |
| LDA addr | 0x01 | 2 | A β RAM[addr] |
| ADD addr | 0x02 | 2 | A β A + RAM[addr] |
| SUB addr | 0x03 | 2 | A β A β RAM[addr] |
| STA addr | 0x04 | 2 | RAM[addr] β A |
| LDI imm | 0x05 | 2 | A β imm (0β255) |
| JMP addr | 0x06 | 2 | PC β addr |
| JC addr | 0x07 | 2 | If CF: PC β addr |
| JZ addr | 0x08 | 2 | If ZF: PC β addr |
| AND addr | 0x09 | 2 | A β A & RAM[addr] |
| OR addr | 0x0A | 2 | A β A | RAM[addr] |
| XOR addr | 0x0B | 2 | A β A ^ RAM[addr] |
| SHL | 0x0C | 1 | A β A << 1, CF=msb |
| SHR | 0x0D | 1 | A β A >> 1, CF=lsb |
| OUT | 0x0E | 1 | OUTPUT β A |
| HLT | 0x0F | 1 | Halt clock |
| PUSH | 0x10 | 1 | RAM[SP]βA; SP-- |
| POP | 0x11 | 1 | SP++; AβRAM[SP] |
| CALL addr | 0x12 | 2 | Push PC; PCβaddr |
| RET | 0x13 | 1 | Pop PC |
| IN | 0x14 | 1 | A β INPUT reg |
| RTI | 0x15 | 1 | Return from interrupt |
| JNZ addr | 0x16 | 2 | If !ZF: PCβaddr |
| JNC addr | 0x17 | 2 | If !CF: PCβaddr |
| LDB imm | 0x18 | 2 | B β imm |
| CMP addr | 0x19 | 2 | Flags only: AβRAM[addr] |
Why Pipelining?
Our SAP-1 is a non-pipelined (sequential) design: each instruction must fully complete before the next one starts. A pipelined CPU overlaps stages, so while Instruction N is executing, Instruction N+1 is being decoded and N+2 is being fetched.
The 3-Stage Classic Pipeline
Hazards
- Data Hazard: Instruction N+1 needs a result that N hasn't finished computing yet. Solved with forwarding or stall bubbles.
- Control Hazard: A branch (JMP/JC) changes PC β instructions already in the pipeline must be flushed. Branch prediction helps here.
- Structural Hazard: Two stages need the same hardware simultaneously (e.g., both IF and EX want RAM). Solved with separate instruction/data caches.
How This CPU Works
This is an extended SAP-1 (Simple As Possible) design inspired by Ben Eater's 8-bit breadboard computer, expanded with a 256-byte RAM, stack, more ALU operations, hardware interrupts, and a full 26-instruction set.
The Fetch-Decode-Execute Cycle
Every instruction runs through the same two fetch micro-steps first:
- T0 β Fetch (Addr): CO+MI β PC drives address bus, MAR latches it
- T1 β Fetch (Data): RO+II+CE β RAM[MAR] β IR, PC++
- T2+ β Execute: Instruction-specific micro-steps
2-byte instructions need an extra operand fetch at T2: CO+MI, then RO+?I+CE to read the operand byte.
The Stack
The stack grows downward from address 0xFF. SP starts at 0xFF. PUSH decrements SP after writing; POP increments SP before reading. CALL automatically pushes the return address; RET pops it.
PUSH: RAM[SP] β A; SP-- POP: SP++; A β RAM[SP] CALL: push PC (return addr); PC β target RET: pop PC
Interrupts
Press the INT button to trigger a hardware interrupt. The CPU saves PC and flags to the stack, then jumps to the interrupt vector at 0xF0. Write your ISR (Interrupt Service Routine) starting at 0xF0 and end it with RTI.
Control Signals
| Signal | Meaning |
|---|---|
| HLT | Halt the clock |
| MI | MAR In β load address from bus |
| RI | RAM In β write bus to RAM[MAR] |
| RO | RAM Out β RAM[MAR] to data bus |
| II | IR In β load data bus into IR |
| AI | A In β load data bus into A |
| AO | A Out β A to data bus |
| BI | B In β load data bus into B |
| BO | B Out β B to data bus |
| EO | ALU Out β ALU result to data bus |
| SU | Subtract mode (ALU) |
| ANDI | AND mode (ALU) |
| ORI | OR mode (ALU) |
| XORI | XOR mode (ALU) |
| SHLI | Shift Left mode (ALU) |
| SHRI | Shift Right mode (ALU) |
| OI | Output In β load data bus into OUT |
| CE | Counter Enable β PC++ |
| CO | Counter Out β PC to bus |
| J | Jump β load PC from bus |
| FI | Flags In β update CF/ZF |
| SPO | SP Out β SP to address bus |
| SPI | SP In β load bus to SP |
| SPD | SP Decrement β SP-- |
| SPUP | SP Increment β SP++ |
| INO | Input Out β INPUT register to data bus |
Architecture Key Facts
- 8-bit data bus β all data in 8-bit chunks
- 8-bit address bus β 256 addressable RAM locations
- Stack: 8-bit SP, grows down from 0xFF
- Interrupt vector: 0xF0 (hardwired)
- Instruction format: opcode byte (1-byte instrs) or opcode + operand (2-byte)
- ALU: ADD, SUB, AND, OR, XOR, SHL, SHR β all 8-bit
CU Signal Reference Sheet
OUTPUT signals β put data onto a bus
| Signal | Name | Build Pin | What it does |
|---|---|---|---|
| CO | Counter Out | PC β ENABLE | PC puts address onto address bus |
| RO | RAM Out | RAM β RD | RAM puts data onto data bus (row MAR points at) |
| AO | A Out | REG A β ENABLE | Register A puts value onto data bus |
| BO | B Out | REG B β ENABLE | Register B puts value onto data bus |
| EO | ALU Out | ALU β ENABLE | ALU puts result onto data bus |
| IO | IR Operand Out | IR β ENABLE | IR puts operand onto address bus |
| SPO | SP Out | SP β ENABLE | Stack pointer puts address onto address bus |
| INO | Input Out | INPUT β ENABLE | Input register puts value onto data bus |
INPUT signals β capture data from a bus
| Signal | Name | Build Pin | What it does |
|---|---|---|---|
| MI | MAR In | MAR β LOAD | MAR captures address from address bus |
| RI | RAM In | RAM β WR | RAM stores data bus value into addressed row |
| AI | A In | REG A β LOAD | Register A captures from data bus |
| BI | B In | REG B β LOAD | Register B captures from data bus |
| II | IR In | IR β LOAD | Instruction Register captures from data bus |
| OI | Output In | OUT β LOAD | Output display captures from data bus |
| SPI | SP In | SP β LOAD | Stack pointer captures from bus |
| FI | Flags In | FLAGS β LOAD | Flags register captures CF and ZF from ALU |
| J | Jump | PC β LOAD | PC captures new address from address bus (jump) |
CONTROL signals β change modes
| Signal | Name | What it does |
|---|---|---|
| CE | Counter Enable | PC increments by 1 (counts up) |
| SU | Subtract | ALU subtracts instead of adds |
| ANDI | AND mode | ALU does bitwise AND |
| ORI | OR mode | ALU does bitwise OR |
| XORI | XOR mode | ALU does bitwise XOR |
| SHLI | Shift Left | ALU shifts bits left (Γ2) |
| SHRI | Shift Right | ALU shifts bits right (Γ·2) |
| SPD | SP Decrement | Stack pointer subtracts 1 (stack grows down) |
| SPUP | SP Up | Stack pointer adds 1 (stack shrinks) |
| HLT | Halt | Stops the clock. CPU freezes. |
Build Mode Pin Guide
| Pin | Meaning | Direction | Notes |
|---|---|---|---|
| LOAD | Let data IN from bus | Input door | CU knocks here to store a value |
| ENABLE | Put data OUT to bus | Output door | CU knocks here to read a value |
| RD | Read (RAM only) | RAM output | Same as ENABLE but for RAM |
| WR | Write (RAM only) | RAM input | Same as LOAD but for RAM |
| INC | Increment (PC only) | Count up | CE signal connects here |
| CLK | Clock input | Timing | Always connected to clock |
| D / DIN | Data input | From bus | Where bus data arrives |
| Q / DOUT | Data output | To bus | Where stored data leaves |
| DIRECT | Always-on output | Hardwired | REG A/B β ALU (no enable needed) |
Hardwired Connections (always active, no CU signal needed)
| From | To | What it does |
|---|---|---|
| MAR | RAM address | RAM always sees MAR's address |
| REG A | ALU input A | ALU always sees A's value |
| REG B | ALU input B | ALU always sees B's value |
| IR | CU opcode input | CU always sees the instruction |
| FLAGS | CU flag input | CU always sees CF and ZF (for JZ/JC) |
| Clock | All components | Always pulsing. Never stops (until HLT). |
Fetch Cycle (T0 + T1 β same for EVERY instruction)
T0: CO + MI PC outputs address β MAR captures T1: RO + II + CE RAM outputs instruction β IR captures, PC++ (T2 onward: depends on the instruction β see Microcode tab)
Learning Tips
- Use Step T+1 to watch one micro-step at a time
- Use the Microcode tab to see β and edit β the control ROM
- Try the Challenges tab for guided exercises
- Click a memory address to set a breakpoint (red dot)
- Check the History tab to replay any past CPU state
- The INT button fires a hardware interrupt β write an ISR at 0xF0
Each test runs a small program and checks the result. If all tests pass, the simulator is reliable β any wrong answer in your own code is YOUR bug, not the CPU's.