Cycles 0
Instructions 0
T-State T0
SP FF
Status READY
200ms
S step I step instr Space run/pause R reset
CPU Diagram
Clock Waveform
Control Signals (active = highlighted red)
Registers
Flags
Carry (CF) 0 Overflow/borrow on arith
Zero (ZF) 0 Result was zero
Buses
Address Bus (8-bit)
00000000
0x00 = 0
Data Bus (8-bit)
00000000
0x00 | Driver: none
Output Display
No output yet. Run a program with OUT instructions.
Select an example or write your own assembly code below.
Instruction Set (Extended SAP-1)
MnemonicOpcodeBytesDescription
NOP0x001No operation
LDA addr0x012A ← RAM[addr]
ADD addr0x022A ← A + RAM[addr]
SUB addr0x032A ← A βˆ’ RAM[addr]
STA addr0x042RAM[addr] ← A
LDI imm0x052A ← imm (0–255)
JMP addr0x062PC ← addr
JC addr0x072If CF: PC ← addr
JZ addr0x082If ZF: PC ← addr
AND addr0x092A ← A & RAM[addr]
OR addr0x0A2A ← A | RAM[addr]
XOR addr0x0B2A ← A ^ RAM[addr]
SHL0x0C1A ← A << 1, CF=msb
SHR0x0D1A ← A >> 1, CF=lsb
OUT0x0E1OUTPUT ← A
HLT0x0F1Halt clock
PUSH0x101RAM[SP]←A; SP--
POP0x111SP++; A←RAM[SP]
CALL addr0x122Push PC; PC←addr
RET0x131Pop PC
IN0x141A ← INPUT reg
RTI0x151Return from interrupt
JNZ addr0x162If !ZF: PC←addr
JNC addr0x172If !CF: PC←addr
LDB imm0x182B ← imm
CMP addr0x192Flags only: Aβˆ’RAM[addr]
Addresses 0x00–0xFF (256 bytes). Stack grows down from 0xFF. Interrupt vector: 0xF0. Labels: name: instr. Comments: ; or //
256 bytes (0x00–0xFF). Click address to toggle breakpoint.
PC MAR Breakpoint SP
0 / 0 solved
Microcode ROM Editor Click a cell to toggle a control signal. Changes take effect immediately.
Each row = one T-state. Each column = one control signal. The fetch cycle (T0, T1) is shared by all instructions. Editing here directly rewrites the CPU's control ROM β€” just like programming a 28C256 EEPROM on the real hardware!
Execution Timeline
Pipeline Visualization How a pipelined CPU overlaps Fetch / Decode / Execute

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

IF β€” Instruction Fetch
PC β†’ MAR, RAM β†’ IR, PC++. Reads the next instruction from memory.
ID β€” Instruction Decode
Opcode decoded, register file read, control signals prepared.
EX β€” Execute
ALU performs operation, memory accessed (for LDA/STA), result written back.

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:

  1. T0 β€” Fetch (Addr): CO+MI β€” PC drives address bus, MAR latches it
  2. T1 β€” Fetch (Data): RO+II+CE β€” RAM[MAR] β†’ IR, PC++
  3. 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

SignalMeaning
HLTHalt the clock
MIMAR In β€” load address from bus
RIRAM In β€” write bus to RAM[MAR]
RORAM Out β€” RAM[MAR] to data bus
IIIR In β€” load data bus into IR
AIA In β€” load data bus into A
AOA Out β€” A to data bus
BIB In β€” load data bus into B
BOB Out β€” B to data bus
EOALU Out β€” ALU result to data bus
SUSubtract mode (ALU)
ANDIAND mode (ALU)
ORIOR mode (ALU)
XORIXOR mode (ALU)
SHLIShift Left mode (ALU)
SHRIShift Right mode (ALU)
OIOutput In β€” load data bus into OUT
CECounter Enable β€” PC++
COCounter Out β€” PC to bus
JJump β€” load PC from bus
FIFlags In β€” update CF/ZF
SPOSP Out β€” SP to address bus
SPISP In β€” load bus to SP
SPDSP Decrement β€” SP--
SPUPSP Increment β€” SP++
INOInput 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
SignalNameBuild PinWhat it does
COCounter OutPC β†’ ENABLEPC puts address onto address bus
RORAM OutRAM β†’ RDRAM puts data onto data bus (row MAR points at)
AOA OutREG A β†’ ENABLERegister A puts value onto data bus
BOB OutREG B β†’ ENABLERegister B puts value onto data bus
EOALU OutALU β†’ ENABLEALU puts result onto data bus
IOIR Operand OutIR β†’ ENABLEIR puts operand onto address bus
SPOSP OutSP β†’ ENABLEStack pointer puts address onto address bus
INOInput OutINPUT β†’ ENABLEInput register puts value onto data bus
INPUT signals β€” capture data from a bus
SignalNameBuild PinWhat it does
MIMAR InMAR β†’ LOADMAR captures address from address bus
RIRAM InRAM β†’ WRRAM stores data bus value into addressed row
AIA InREG A β†’ LOADRegister A captures from data bus
BIB InREG B β†’ LOADRegister B captures from data bus
IIIR InIR β†’ LOADInstruction Register captures from data bus
OIOutput InOUT β†’ LOADOutput display captures from data bus
SPISP InSP β†’ LOADStack pointer captures from bus
FIFlags InFLAGS β†’ LOADFlags register captures CF and ZF from ALU
JJumpPC β†’ LOADPC captures new address from address bus (jump)
CONTROL signals β€” change modes
SignalNameWhat it does
CECounter EnablePC increments by 1 (counts up)
SUSubtractALU subtracts instead of adds
ANDIAND modeALU does bitwise AND
ORIOR modeALU does bitwise OR
XORIXOR modeALU does bitwise XOR
SHLIShift LeftALU shifts bits left (Γ—2)
SHRIShift RightALU shifts bits right (Γ·2)
SPDSP DecrementStack pointer subtracts 1 (stack grows down)
SPUPSP UpStack pointer adds 1 (stack shrinks)
HLTHaltStops the clock. CPU freezes.
Build Mode Pin Guide
PinMeaningDirectionNotes
LOADLet data IN from busInput doorCU knocks here to store a value
ENABLEPut data OUT to busOutput doorCU knocks here to read a value
RDRead (RAM only)RAM outputSame as ENABLE but for RAM
WRWrite (RAM only)RAM inputSame as LOAD but for RAM
INCIncrement (PC only)Count upCE signal connects here
CLKClock inputTimingAlways connected to clock
D / DINData inputFrom busWhere bus data arrives
Q / DOUTData outputTo busWhere stored data leaves
DIRECTAlways-on outputHardwiredREG A/B β†’ ALU (no enable needed)
Hardwired Connections (always active, no CU signal needed)
FromToWhat it does
MARRAM addressRAM always sees MAR's address
REG AALU input AALU always sees A's value
REG BALU input BALU always sees B's value
IRCU opcode inputCU always sees the instruction
FLAGSCU flag inputCU always sees CF and ZF (for JZ/JC)
ClockAll componentsAlways 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
CPU Verification Suite
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.
Components
SANDBOX
100%
Select a component to inspect its pins and values.
Build Challenges
0 / 8 solved
Why this matters
Required Components
The solution is shown when you click "Show Solution".
Clock
Speed 400ms
Board
Working CPU Template
Load a fully-wired CPU with color-coded wires, labels, and a test program ready to run.
Green = Clock wires
Amber = Data bus
Blue = Address bus
Red = Control signals
Orange = ALU / Flags
Purple = Feedback to CU
Tips
Drag chips from the left panel
Click an OUTPUT pin to start a wire
Click an INPUT pin to finish it
Right-click a wire to delete it
Double-click a Switch to toggle it
Double-click any chip to rename it
Space = Pulse clock
Del = Delete selected
Esc = Cancel wire
Scroll = zoom, drag empty space = pan
Simulation Log
Signal & Pin Reference Sheet
OUTPUT signals (put data onto bus)
CO β†’ PC:ENABLE   RO β†’ RAM:RD   AO β†’ REGA:ENABLE
BO β†’ REGB:ENABLE   EO β†’ ALU:ENABLE   IO β†’ IR:ENABLE
SPO β†’ SP:ENABLE   INO β†’ INPUT:ENABLE
INPUT signals (capture from bus)
MI β†’ MAR:LOAD   RI β†’ RAM:WR   AI β†’ REGA:LOAD
BI β†’ REGB:LOAD   II β†’ IR:LOAD   OI β†’ OUT:LOAD
FI β†’ FLAGS:LOAD   J β†’ PC:LOAD   SPI β†’ SP:LOAD
CONTROL signals
CE β†’ PC:INC   SU β†’ ALU subtract   HLT β†’ stop clock
SPD β†’ SP-1   SPUP β†’ SP+1
ANDI ORI XORI SHLI SHRI β†’ ALU modes
Pin meanings
LOAD = input door (capture from bus on clock beat)
ENABLE = output door (drive value onto bus)
RD = RAM read (same as ENABLE for RAM)
WR = RAM write (same as LOAD for RAM)
INC = PC counts up by 1
DIRECT = always-on output (REG→ALU, no enable needed)
Always on (no CU signal needed)
MARβ†’RAM address   REGAβ†’ALU   REGBβ†’ALU
IRβ†’CU opcode   FLAGSβ†’CU   Clockβ†’all
Fetch cycle (every instruction)
T0: CO+MI   T1: RO+II+CE
Select a component above
to read its datasheet.
Rename Component
Current Instruction β€” step to see micro-step detail