Custom 16-bit RISC-style instruction set architecture and Verilog CPU implementation for a small unified-memory processor.
The design targets a simple teaching-scale machine:
- 16-bit instructions and 16-bit data path
- 8 programmer-visible registers
- 16 total instructions
- 1024-word unified memory
- Single-cycle style datapath with separate control and datapath modules
The repository includes synthesizable RTL, simulation testbenches, and a full technical report describing the ISA, encoding, implementation, and results.
The processor uses three instruction formats:
R-type: register-register ALU ops plus short-immediate ALU opsLS-type: base+offset load/storeIJ-type: large immediate, branch, and jump operations
Register set:
r0/$zero: hardwired zeror1-r6: general-purpose registersr7/$ra: link register for subroutine return
Instruction set:
| Opcode / funct | Mnemonic | Description |
|---|---|---|
000 / 000 |
ADD |
rd <- rs + rt |
000 / 001 |
SUB |
rd <- rs - rt |
000 / 010 |
AND |
rd <- rs & rt |
000 / 011 |
OR |
rd <- rs | rt |
000 / 100 |
SLT |
rd <- (rs < rt) |
000 / 101 + iflag=1 |
SLL |
rd <- rs << imm3 |
000 / 110 + iflag=1 |
SRL |
rd <- rs >> imm3 |
000 / 000 + iflag=1 |
ADDI |
rd <- rs + imm3 |
001 |
ST |
M[rs + imm7] <- rt |
010 |
LD |
rt <- M[rs + imm7] |
011 |
LDI |
rd <- imm10 |
100 |
BEZ |
branch if register is zero |
101 |
BNZ |
branch if register is non-zero |
110 |
JL |
jump and link |
111 |
JR |
jump to register |
000 / 111 |
HALT |
stop execution |
.
├── README.md
├── Report/
│ ├── Custom ISA Technical Report.pdf
│ └── main.tex
├── Synthesis/
│ ├── cpu.v
│ ├── control_unit.v
│ ├── unified_mem.v
│ ├── isa.v
│ └── ...
└── Testbench/
├── cpu_tb.v
├── cpu_flow_tb.v
└── ...
Key files:
Synthesis/cpu.v: top-level CPU datapath and control integrationSynthesis/control_unit.v: opcode/funct decode and control signalsSynthesis/unified_mem.v: 1024-word unified instruction/data memorySynthesis/isa.v: FPGA wrapper for the CPUTestbench/cpu_tb.v: instruction-by-instruction execution testTestbench/cpu_flow_tb.v: control-flow-oriented program testReport/main.tex: full written design report
The repository does not include a build script, but the testbench directory is set up to compile directly with a Verilog simulator.
Example with Icarus Verilog:
iverilog -g2012 -o tb_cpu.out Testbench/*.v -s tb_cpu
vvp tb_cpu.outiverilog -g2012 -o tb_cpu_flow.out Testbench/*.v -s tb_cpu_flow
vvp tb_cpu_flow.outWhat the included testbenches cover:
tb_cpu: arithmetic, logic, shifts, memory, branches, jump-and-link, returntb_cpu_flow: if/else, while loop, for loop, and function call/return flow
Note: simulator binaries are not installed in this workspace, so the example commands above were documented from the source layout but not executed here.
The Quartus project files in Synthesis/ target:
- Intel Quartus Prime Lite 22.1
Cyclone IV E- Device
EP4CE115F29C7
The top-level FPGA module is Synthesis/isa.v. It divides the CLOCK_50
input down to a slower CPU clock and drives LEDG8 as a visible heartbeat.
- Memory is unified: instructions and data share the same 1024-word array.
- Register
r0is forced to zero on every clock edge. JLwritesPC + 1intor7, andJRreturns through a register target.- Short immediates use the
iflagbit in theR-typeencoding.
For the full project documentation, see:
The report includes:
- ISA specification and encodings
- mapping from C constructs to the custom ISA
- RTL design discussion
- simulation output
- synthesis and hardware implementation results