A fully functional single-cycle RISC-V processor implemented in Verilog, supporting all 37 base integer (RV32I) instructions. Built for learning and FPGA prototyping.
| Type | Instructions |
|---|---|
| R-type | ADD, SUB, AND, OR, XOR, SLL, SRL, SRA, SLT, SLTU |
| I-type (ALU) | ADDI, ANDI, ORI, XORI, SLTI, SLTIU, SLLI, SRLI, SRAI |
| I-type (Load) | LB, LH, LW, LBU, LHU |
| S-type (Store) | SB, SH, SW |
| B-type (Branch) | BEQ, BNE, BLT, BGE, BLTU, BGEU |
| U-type | LUI, AUIPC |
| J-type | JAL, JALR |
├── rtl/
│ ├── core/
│ │ ├── processor.v # Top-level datapath (connects all modules)
│ │ ├── PC.v # Program counter register
│ │ ├── PC_adder.v # PC + 4 adder
│ │ ├── register_file.v # 32 x 32-bit register file
│ │ └── imm_gen.v # Immediate generator for all formats
│ ├── control/
│ │ └── main_control_unit.v # Opcode decoder → control signals
│ ├── execution/
│ │ ├── ALU.v # 10-operation ALU
│ │ └── ALU_control_unit.v # ALUOp + funct3/funct7 → ALU select
│ ├── memory/
│ │ ├── instruction_mem.v # Instruction ROM (loads program.mem)
│ │ ├── data_memory.v # Data RAM with byte/half/word access
│ │ └── data.mem # Initial data memory contents
│ └── utils/
│ ├── adder.v # Generic 32-bit adder
│ ├── mux.v # 2-to-1 multiplexer
│ └── mux4to1.v # 4-to-1 multiplexer
├── sim/
│ └── tb_processor.v # Testbench with debug signal outputs
├── demo_programs/
│ ├── bubble_sort/program.mem # Bubble sort demo (default)
│ └── sum_of_n_natural_nums/program.mem
├── fpga/
│ └── constraints/constraints.xdc # Pin constraints (Zynq/Zedboard-style)
└── images/
Each clock cycle executes one instruction through the full datapath:
- Fetch — PC addresses instruction memory; PC+4 is computed in parallel.
- Decode — Opcode drives the main control unit; the immediate generator sign-extends fields; register file reads
rs1andrs2. - Execute — ALU performs the operation selected by the ALU control unit. Source muxes choose between register values, PC, zero, or immediates.
- Memory — Data memory performs load/store with byte, halfword, or word granularity based on
funct3. - Write-back — A 4-to-1 mux selects the write-back value: ALU result, memory read data, or PC+4 (for JAL/JALR).
- Next PC — A 4-to-1 mux picks the next PC from: PC+4, branch target, JAL target, or JALR target.
The default demo program sorts a 5-element array in data memory using bubble sort.
Program: demo_programs/bubble_sort/program.mem
The assembly initializes data memory with the values {2, 3, 9, 1, 5}, then runs nested loops to sort them in ascending order using compare-and-swap.
- Open
sim/tb_processor.vin your simulator (Vivado, ModelSim, etc.). - The instruction memory automatically loads
program.mem. - Run the simulation — all debug signals (PC, instruction, control signals, ALU result, branch decisions) are exposed as top-level outputs for waveform inspection.
The design is constrained for an FPGA board with 8 LEDs and a toggle switch.
- Switch (SW): selects what is displayed on the LEDs — toggle between the program counter value and control signals.
- LEDs [7:0]: show the selected view.
- Reset button: resets the processor to PC = 0.
Pin assignments are defined in fpga/constraints/constraints.xdc.



