Karim Mohamed

Index

  1. 01Homestart here
  2. 02Researchrun the testbenches
  3. 03Workshopthings to poke
  4. 04Venturescompanies
  5. 05Experiencethe files
  6. 06About meand what’s on now
  7. 07Off the clockplay a game

More

Seattle · ·

GitHubLinkedInContact
Technical specificationNot peer reviewedPublished in a public repository

RISC8 architecture specification

Instruction set, datapath, timing and verification of a cycle-accurate 8-bit RISC core

Authors
Karim Mohamed
Published
· updated
Reading time
4 min

Machine model

ResourceWidth / size
Program counter8 bits, wraps at 255 → 0
Register fileR0–R7, 8 bits each; R0 hardwired to 0; 2 read ports, 1 write port
FlagsZ (zero), N (bit 7), C (carry / no-borrow / last bit shifted out)
Instruction memory256 × 16-bit words, read-only; unused words hold HLT
Data memory256 × 8-bit bytes

The instruction word is 16 bits; the datapath is 8. That split keeps the encoding roomy enough for three register fields while the arithmetic stays small enough to verify exhaustively.

Instruction encoding

 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
+------+-----+-----+-----+-----+
opMnemonicEffectFlags
0000NOPnothing
0001ADD rd, rs1, rs2rd = rs1 + rs2ZNC
0010SUB rd, rs1, rs2rd = rs1 − rs2 (C = 1 if no borrow)ZNC
0011AND rd, rs1, rs2rd = rs1 & rs2ZN, C = 0
0100OR rd, rs1, rs2rd = rs1 | rs2ZN, C = 0
0101XOR rd, rs1, rs2rd = rs1 ^ rs2ZN, C = 0
0110SHL rd, rs1, nrd = rs1 ≪ n, logicalZNC
0111SHR rd, rs1, nrd = rs1 ≫ n, zero fillZNC
1000LDI rd, imm8rd = imm8
1001ADDI rd, imm8rd = rd + imm8ZNC
1010LD rd, [rs1]rd = mem[rs1]
1011ST rd, [rs1]mem[rs1] = rd
1100JMP imm8PC = imm8
1101BZ rd, imm8if rd = 0: PC = imm8
1110BNZ rd, imm8if rd ≠ 0: PC = imm8
1111HLTstop

The assembler accepts the pseudo-instruction MOV rd, rs, encoded as ADD rd, rs, R0, and labels as branch targets.

Timing

Every instruction takes exactly four clock cycles, one per state. Values that hardware would hold between states live in explicit latches (IR, NPC, A, B, ALU, MDR), which is what lets the trace show precisely what changed on each edge.

StateWork done on the clock edge
IFIR ← IMEM[PC], PC ← PC + 1
IDslice fields, look up the control ROM, read ports into latches A and B
EXALU operation into ALU; data-memory read into MDR or write; resolve branch
WBwrite rd and flags; on a taken branch PC ← imm8; HLT stops the clock

Because CPI is fixed, the cycle count of any run is exactly 4n4n for nn retired instructions.

The ALU, at gate level

Addition uses an 8-bit ripple-carry chain of full adders. For bit ii with inputs ai,bia_i, b_i and carry-in cic_i:

si=ai⊕bi⊕ci,ci+1=aibi+ci(ai⊕bi).s_i = a_i \oplus b_i \oplus c_i, \qquad c_{i+1} = a_i b_i + c_i (a_i \oplus b_i).

Subtraction reuses the adder as a+b‾+1a + \overline{b} + 1, so the carry out is 1 exactly when a≥ba \ge b (no borrow). Logical shifts pass through three 2:1 multiplexer stages that shift by 1, 2 and 4, each enabled by one bit of the shift amount; the carry flag captures the last bit shifted out. AND, OR and XOR clear C.

Verification

  1. Exhaustive ALU checks. All 65,536 input pairs for ADD and SUB are compared with native integer arithmetic; shifts are checked for every value and amount.
  2. Two engines. A functional fast core (about 13× faster) runs one loop iteration per instruction. Both cores must end in identical architectural state.
  3. Golden trace. The Fibonacci program stores F0…F13F_0 \ldots F_{13} (0 to 233, the largest that fits in 8 bits) in data memory. It retires 103 instructions in 412 cycles, and the full cycle trace is compared byte-for-byte with a stored golden copy.

The suite has 26 tests. The TypeScript port on this site runs the same 26, including the byte-for-byte trace comparison.

Known limitations

No call/return or stack, no interrupts, no signed-overflow flag, no pipelining and no hardware description. The next study is a five-stage pipelined variant with hazard detection and forwarding, measured against this core on the same programs.

Cite this document

Karim Mohamed. “RISC8 architecture specification.” Technical specification, 2026. https://karim-mohamed.dev/research/papers/risc8-specification

Esc
  • Homestart here
  • Researchrun the testbenches
  • Workshopthings to poke
  • Venturescompanies
  • Experiencethe files
  • About meand what’s on now
  • Off the clockplay a game
  • My deskclick the objects
  • Field notesdated entries
  • Nowthis season
  • Changeloghow it grew
  • Photographycamera roll
  • Failure-aware manipulation
  • MalaBoost
  • RISC8 processor
  • Writing
  • Contact
  • Terminal
  • Colophon
  • Failure-aware robotic manipulationRobotics · In development
  • MalaBoostDiagnostics · Proposed design, Simulation
  • RISC8, a processor from the gates upComputer architecture · Simulation
  • Catalytic enhancement for faint pLDH linesResearch design · not peer reviewed
  • RISC8 architecture specificationTechnical specification
  • RushdFounder & CEO
  • Preventa HomeCo-founder
  • DaythreadBuilt the product on a hackathon team
  • Run the RISC8 processorguided tours
  • Make the robot arm sliptestbench
  • Rescue a faint malaria test lineMalaBoost model
  • Logic gates, adders & a puzzle
  • Watch the worst-case carry
  • Take a penaltythe keeper learns
  • ? Some pages have a key just under Esc.not yet
  • ? Two keys, one of them is K.not yet
  • ? The terminal can run a diagnostic.not yet
  • ? Referees are allowed a second look. So is the terminal.not yet
  • ? Every card is hiding a constraint.not yet
  • ? The footer is saying something.not yet
  • ? Seven cards on About. All of them.not yet

40 results

terminal · ` or Esc to close