RISC8 architecture specification
Instruction set, datapath, timing and verification of a cycle-accurate 8-bit RISC core
Machine model
| Resource | Width / size |
|---|---|
| Program counter | 8 bits, wraps at 255 → 0 |
| Register file | R0–R7, 8 bits each; R0 hardwired to 0; 2 read ports, 1 write port |
| Flags | Z (zero), N (bit 7), C (carry / no-borrow / last bit shifted out) |
| Instruction memory | 256 × 16-bit words, read-only; unused words hold HLT |
| Data memory | 256 × 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
+------+-----+-----+-----+-----+
| op | Mnemonic | Effect | Flags |
|---|---|---|---|
0000 | NOP | nothing | |
0001 | ADD rd, rs1, rs2 | rd = rs1 + rs2 | ZNC |
0010 | SUB rd, rs1, rs2 | rd = rs1 − rs2 (C = 1 if no borrow) | ZNC |
0011 | AND rd, rs1, rs2 | rd = rs1 & rs2 | ZN, C = 0 |
0100 | OR rd, rs1, rs2 | rd = rs1 | rs2 | ZN, C = 0 |
0101 | XOR rd, rs1, rs2 | rd = rs1 ^ rs2 | ZN, C = 0 |
0110 | SHL rd, rs1, n | rd = rs1 ≪ n, logical | ZNC |
0111 | SHR rd, rs1, n | rd = rs1 ≫ n, zero fill | ZNC |
1000 | LDI rd, imm8 | rd = imm8 | |
1001 | ADDI rd, imm8 | rd = rd + imm8 | ZNC |
1010 | LD rd, [rs1] | rd = mem[rs1] | |
1011 | ST rd, [rs1] | mem[rs1] = rd | |
1100 | JMP imm8 | PC = imm8 | |
1101 | BZ rd, imm8 | if rd = 0: PC = imm8 | |
1110 | BNZ rd, imm8 | if rd ≠ 0: PC = imm8 | |
1111 | HLT | stop |
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.
| State | Work done on the clock edge |
|---|---|
| IF | IR ← IMEM[PC], PC ← PC + 1 |
| ID | slice fields, look up the control ROM, read ports into latches A and B |
| EX | ALU operation into ALU; data-memory read into MDR or write; resolve branch |
| WB | write 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 for retired instructions.
The ALU, at gate level
Addition uses an 8-bit ripple-carry chain of full adders. For bit with inputs and carry-in :
Subtraction reuses the adder as , so the carry out is 1 exactly when (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
- 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.
- Two engines. A functional fast core (about 13× faster) runs one loop iteration per instruction. Both cores must end in identical architectural state.
- Golden trace. The Fibonacci program stores (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