This project is a hardware description built to demonstrate how to implement a fully functional RISC-V RV32I processor using a single-cycle architecture.
It serves as an educational reference and FPGA-ready design and showcases how to:
- π Execute RV32I base integer instructions in a single clock cycle
- β‘ Interface with 7-segment displays via memory-mapped I/O
- π§ Implement modular CPU components (ALU, Control Unit, Registers, etc.)
- π¨ Support branch and jump instructions with dedicated Branch Unit
- π¦ Load custom programs from hex files into instruction memory
- π Deploy to Intel/Altera FPGAs with Quartus Prime
| Feature | Description |
|---|---|
| RV32I Base Instructions | Supports R-type, I-type, S-type, B-type, U-type, and J-type instructions |
| Single-Cycle Design | Each instruction completes in exactly one clock cycle |
| Memory-Mapped I/O | 7-segment display imlemented via memory-mapped address |
| Modular Architecture | Each component (ALU, Control, Registers) is a separate testable module |
| FPGA Ready | Includes wrapper module for direct synthesis to Intel/Altera FPGAs |
| Simulation Support | Testbenches included for all modules with VCD waveform generation |
risc-v_single_cycle_processor/
βββ ALU/ # Arithmetic Logic Unit
β βββ ALU.sv # 32-bit ALU with 10 operations
β βββ ALU_tb.sv # ALU testbench
β
βββ BranchUnit/ # Branch condition evaluation
β βββ BranchUnit.sv # Evaluates BEQ, BNE, BLT, BGE, etc.
β βββ BranchUnit_tb.sv # Branch Unit testbench
β
βββ ControlUnit/ # Instruction decoder
β βββ ControlUnit.sv # Generates control signals from OpCode
β βββ ControlUnit_tb.sv # Control Unit testbench
β
βββ DataMemory/ # Data RAM (8 KiB)
β βββ DataMemory.sv # Supports LB, LH, LW, SB, SH, SW
β βββ DataMemory_tb.sv # Data Memory testbench
β
βββ ImmGen/ # Immediate value generator
β βββ ImmGen.sv # Sign-extends immediates for all formats
β βββ ImmGen_tb.sv # Immediate Generator testbench
β
βββ InstructionMemory/ # Program ROM
β βββ InstructionMemory.sv # Loads programs from .hex files
β βββ InstructionMemory_tb.sv # Instruction Memory testbench
β
βββ ProgramCounter/ # PC register
β βββ ProgramCounter.sv # 32-bit program counter with reset
β βββ ProgramCounter_tb.sv # Program Counter testbench
β
βββ RegistersUnit/ # Register file (x0-x31)
β βββ RegistersUnit.sv # 32 registers, dual read, single write
β βββ RegistersUnit_tb.sv # Registers Unit testbench
β
βββ muxs/ # Multiplexers
β βββ ALUA.sv # ALU input A selector (PC or rs1)
β βββ ALUB.sv # ALU input B selector (rs2 or Imm)
β βββ NextPC.sv # Next PC selector (PC+4 or ALURes)
β βββ RUDataWr.sv # Register write data selector
β
βββ I_O_Implementation/ # FPGA I/O modules
β βββ RiscV_SingleCycle_FPGA.sv # β Top module for FPGA synthesis
β βββ RiscV_SingleCycle_FPGA_tb.sv # FPGA wrapper testbench
β βββ test_display.sh # Script to test display modules (Linux)
β βββ test_display.bat # Script to test display modules (Windows)
β βββ SevenSegmentDisplay/ # 7-segment display drivers
β β βββ SevenSegmentDisplay.sv # Hex to 7-segment decoder
β β βββ DisplayController.sv # 8-display controller for 32-bit values
β β βββ *_tb.sv # Testbenches for display modules
β βββ 7_segments_test/ # Standalone 7-segment test project
β β βββ SevenSegTest.sv # Simple test for FPGA displays
β β βββ SevenSegTest.qpf/.qsf # Quartus project files
β β βββ test_seven_seg.sh/.bat # Test scripts
β βββ programs/ # FPGA-specific programs
β βββ display_test.hex # Test program for 7-segment display
β
βββ diagram/ # Architecture diagrams
β βββ risc-v_diagram.png # Processor block diagram
β
βββ test_programs/ # Assembly programs in binary format
β βββ program.hex # Default test program
β
βββ RiscV_SingleCycle.sv # Main processor module (simulation)
βββ RiscV_SingleCycle_tb.sv # Top-level testbench
βββ Risc-V_processor.qpf # Quartus project file
βββ Risc-V_processor.qsf # Quartus settings file
βββ run_test.sh # Script to run simulation (Linux)
βββ run_test.bat # Script to run simulation (Windows)
| Type | Instructions |
|---|---|
| R-type | ADD, SUB, AND, OR, XOR, SLL, SRL, SRA, SLT, SLTU |
| I-type | ADDI, ANDI, ORI, XORI, SLTI, SLTIU, SLLI, SRLI, SRAI |
| Load | LB, LH, LW, LBU, LHU |
| Store | SB, SH, SW |
| Branch | BEQ, BNE, BLT, BGE, BLTU, BGEU |
| Jump | JAL, JALR |
| Upper | LUI, AUIPC |
- Icarus Verilog (iverilog) - For simulation
- GTKWave (optional) - For waveform visualization
- Intel Quartus Prime - For FPGA synthesis (optional)
-
Clone this repository
git clone https://github.com/MateoMor/risc-v_single_cycle_processor.git cd risc-v_single_cycle_processor -
Run the processor simulation
# Linux/macOS chmod +x run_test.sh ./run_test.sh # Windows run_test.bat
-
Test the 7-segment display modules
# Linux/macOS cd I_O_Implementation chmod +x test_display.sh ./test_display.sh # Windows cd I_O_Implementation test_display.bat
-
View waveforms (optional)
gtkwave riscv_tb.vcd
- Open Intel Quartus Prime
- Open the project file
Risc-V_processor.qpf - Set
I_O_Implementation/RiscV_SingleCycle_FPGA.svas the top-level entity - Assign pins according to your FPGA board (DE2-115, DE10-Lite, etc.)
- Compile and program the FPGA
Note: A standalone 7-segment test project is available in
I_O_Implementation/7_segments_test/for testing display functionality independently.
| Category | Technology |
|---|---|
| HDL | SystemVerilog (IEEE 1800-2012) |
| Simulator | Icarus Verilog |
| Waveform Viewer | GTKWave |
| FPGA Toolchain | Intel Quartus Prime |
| Target FPGAs | Intel Cyclone IV/V, MAX 10 |
| Address Range | Description |
|---|---|
0x00000000 - 0x00001FFF |
Data Memory (8 KiB) |
0xFFFFFFFC |
7-Segment Display (write-only) |
This project is designed to be reusable.
You can fork or clone it and adapt it to your own needs by:
- π§ Add new instructions: Extend
ControlUnit.svandALU.svfor M/F extensions - π¨ Change I/O peripherals: Modify
RiscV_SingleCycle_FPGA.svfor LEDs, switches, UART - π Port to other FPGAs: Adjust pin assignments for Xilinx, Lattice, etc.
- βοΈ Increase memory: Modify
DataMemory.svandInstructionMemory.svparameters
It works well as a starter boilerplate for computer architecture courses, FPGA learning, and RISC-V experimentation.
Source: "Arquitectura de Computadoras con RISC-V" by Jaramillo Villegas et al., Universidad TecnolΓ³gica de Pereira
Based on "Arquitectura de Computadoras con RISC-V" by Jaramillo Villegas et al., Universidad TecnolΓ³gica de Pereira.
For further reading, see the official publication: Arquitectura de Computadoras con RISC-V by Jaramillo Villegas et al., available through the Universidad TecnolΓ³gica de Pereira repository.
This project is licensed under the MIT License - see the LICENSE file for details.
Β© 2025 Mateo Morales
