A clean and modular RV32I RISC-V processor core implemented entirely in Verilog for learning, experimentation, and CPU architecture exploration.
This project includes a fully working single-cycle CPU, complete with datapath components, control logic, instruction/data memories, and simulation testbenches.
This is designed as a beginner-friendly but structurally accurate CPU, suitable for:
- Computer architecture learning
- RTL design practice
- FPGA experimentation (future work)
- Extending into a pipelined CPU
- Zero-Knowledge Proof (ZKP) hardware modeling
Below is the block-level flow of the single-cycle RV32I core:
Implements arithmetic & logic operations:
- ADD, SUB
- AND, OR, XOR
- SLT (signed compare)
- Extendable to shifts & more RV32I ops
ALUOpselects the operation
Generates control signals based on:
opcode,funct3,funct7
Supports:
- R-type: ADD, SUB, AND, OR, XOR, SLT
- I-type: ADDI, ANDI, ORI, XORI
- Load: LW
- Store: SW
- LUI
- Branches: BEQ, BNE, BLT, BGE
Outputs:
RegWrite,ALUSrc,MemRead,
MemWrite,MemToReg,Branch,ALUOp
Decodes immediates for:
- I-type
- S-type
- B-type
- U-type
Fully sign-extended per RV32I spec.
- 32 registers (x0–x31)
- Synchronous write
- Asynchronous read
x0hardwired to zero
- Byte-addressable
- Loads program from
program.hex - Uninitialized bytes default to NOP (
0x00000013)
- Supports LW and SW
- Word-aligned addressing (
addr[9:2]) - Simple behavioral RAM
Implements:
- Program Counter
- Instruction Fetch
- Register Read
- Immediate Decode
- ALU
- Memory Access
- Write-Back
- Branch decision logic
Fully compatible with your other RTL modules.
iverilog -o cpu \
tb_single_cycle.v \
rv32_single_cycle.v \
alu.v control.v regfile.v imm_gen.v instr_mem.v data_mem.v
vvp cpu
gtkwave single_cycle.vcdThe CPU fetches instructions from instr_mem using:
$readmemh("program.hex", mem);
The file must contain 1 byte per line in little-endian order.
Example:
93
00
00
00 # addi x1, x0, 0You can generate this from C or assembly using the RISC-V toolchain.
Thanks to the RISC-V community, open-source hardware researchers, and classic architecture texts (Patterson & Hennessy).
