RISC8, a processor from the gates up
Computer architecture · digital logic · verification
Run my processor
hit a tour, or step the clock yourself with S
what you’re looking atMy processor running real programs: tap a tour, or press Step clock to move one clock tick at a time.
The reference program from the repository: F(0)…F(13) into memory 0–13. 103 instructions, 412 cycles.
- IFFetch
- IDDecode
- EXExecute
- WBWriteback
Registers
| R0 | 0 hardwired | 00000000 |
|---|---|---|
| R1 | 00000000 | |
| R2 | 00000000 | |
| R3 | 00000000 | |
| R4 | 00000000 | |
| R5 | 00000000 | |
| R6 | 00000000 | |
| R7 | 00000000 |
Registers are editable between clock cycles. Changes made after decode reach the next instruction, because operands are latched at ID.
Instruction register
0000000000000000
NOP
- op
- NOP (0)
- rd
- R0
- rs1
- R0
- rs2 / shamt
- 0
- imm8
- 0
Control signals
- aluOp—
- regWritefalse
- flagsWritefalse
- memReadfalse
- memWritefalse
- branch—
- haltfalse
Data memory · 256 bytes (hex)
Instruction memory
Cycle trace · same format as the original simulator
cycle st PC IR R0 R1 R2 R3 R4 R5 R6 R7 ZNC | changes
01 · the question
What does a processor actually do on every clock edge, and can I build one honest enough to prove it?
02 · where it stands
- tests passing, in the original and in the browser port
- 26/26
- clock cycles for Fibonacci, matching the golden trace byte for byte
- 412
- clock states per instruction: readable, but no pipeline yet
- 4
03 · what broke → what’s next
- Multi-cycle is slow: every instruction costs four clocks, even a NOP.
- An 8-bit datapath wraps at 255, so the Fibonacci demo stops at F(13) = 233.
- A five-stage pipeline with hazard detection and forwarding, checked against the same golden traces.
- Describe it in an HDL so it could run on an FPGA. None of that exists yet.
Read the full write-up8 sections · Why a processor, Instruction set, Registers & memory…
Why build a processor?
Every program I’d written ran on a machine I’d never really looked inside. I wanted to see, one clock edge at a time, what a processor actually does between fetching a word and writing a result: which latch changes, which flag flips, which bit falls out of a shift.
So I designed a small one and wrote a simulator honest enough that its output reads like a logic-analyser capture. The original is Python; what runs on this page is a line-for-line TypeScript port that passes the same tests.
to be precise: 16-bit instruction words, 8-bit datapath.
The instruction set
Sixteen opcodes, each one 16-bit word: a 4-bit opcode, then up to three 3-bit register fields or an 8-bit immediate. The decoder slices every field at once, the way hardware would; a control ROM decides which fields an opcode actually uses.
15 12 11 9 8 6 5 3 2 0 +------+-----+-----+-----+-----+ | op | rd | rs1 | rs2 | 000 | R-type ADD SUB AND OR XOR | op | rd | rs1 |shamt| 000 | S-type SHL SHR | op | rd | rs1 | 000000 | M-type LD ST | op | rd |0| imm8 | I-type LDI ADDI JMP BZ BNZ | op | 000000000000 | N-type NOP HLT
| Instruction | Effect | Flags |
|---|---|---|
| NOP | nothing | |
| ADD rd, rs1, rs2 | rd = rs1 + rs2 | ZNC |
| SUB rd, rs1, rs2 | rd = rs1 − rs2 | ZNC |
| AND / OR / XOR | bitwise | ZN, C=0 |
| SHL / SHR rd, rs1, n | logical shift by 0–7 | ZNC |
| LDI rd, imm8 | rd = imm8 | |
| ADDI rd, imm8 | rd = rd + imm8 | ZNC |
| LD rd, [rs1] | rd = mem[rs1] | |
| ST rd, [rs1] | mem[rs1] = rd | |
| JMP imm8 | PC = imm8 | |
| BZ / BNZ rd, imm8 | branch if rd = 0 / ≠ 0 | |
| HLT | stop the clock |
Registers and memory
Eight registers, R0 = 0
R0–R7, 8 bits each, two read ports and one write port. R0 is hardwired to zero, so MOV rd, rs is just ADD rd, rs, R0, and needs no opcode of its own.
Two memories
256 × 16-bit instruction memory (read-only; unused words hold HLT, so a runaway program counter stops) and 256 bytes of data memory. Flags: Z, N and C.
The ALU, by hand
ADD and SUB go through eight full adders written as gate equations: sum = a ⊕ b ⊕ c, carry = ab + c(a ⊕ b). Shifts go through a three-stage barrel shifter made of 2:1 multiplexers. This panel runs that exact code.
Eight full adders in a row. Click bits to watch the carries change.
Execution stages
Each instruction takes exactly four clock states, one after another. They do not overlap: this is a multi-cycle machine, not a pipeline. That made every intermediate value visible in the trace.
- IF IR ← IMEM[PC], PC ← PC + 1
- ID slice fields, look up the control ROM, read registers into latches A and B
- EX run the ALU, read or write data memory, decide the branch
- WB write the register and flags, redirect the PC if a branch was taken, stop on HLT
Verification
- Exhaustive ALU tests: every one of the 65,536 input pairs for ADD, SUB and the logic operations is checked against native arithmetic; shifts for every value and amount.
- Two engines: a functional fast core (about 13× faster) must end in exactly the same state as the cycle-accurate one.
- A golden trace: the Fibonacci program (F(0)…F(13), 103 instructions, 412 cycles) is compared byte for byte against a stored trace.
- 26 tests in the original; the port on this page passes the same 26.
Source on GitHub · Architecture specification · The golden trace
Limitations
- It’s a simulator: no hardware description, no timing analysis, no synthesis.
- No call/return or stack, no interrupts, no signed-overflow flag.
- Four states per instruction, every time: simple and readable, but slow.
FPGA and next steps
Next is a five-stage pipelined version with hazard detection and forwarding, compared against this core on the same programs. After that, describing it in an HDL and checking the hardware model against the same golden traces, which would make an FPGA implementation possible. None of that exists yet; it hasn’t been on an FPGA or in silicon.
Research log
Dated entries from the research notebook.
- Nov 10, 2026MilestoneArchitecture schematic and pipeline timeline
- Nov 9, 2026DecisionDecision: multi-cycle, not pipelined (yet)
- Nov 9, 2026MilestoneRISC8 simulator: first version