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

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
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
Select a component above
to read its datasheet.
Rename Component
Current Instruction — step to see micro-step detail