A complete, single-cycle 32-bit RISC-V processor built from scratch in Verilog. This project implements a custom Harvard architecture with Memory-Mapped I/O (MMIO), custom hardware datapath upgrades for subroutines, and mathematically verified branch logic.
Designed and deployed on a Basys 3 Artix-7 FPGA running at a 10 MHz hardware clock.
- Architecture: 32-Bit Single-Cycle RISC-V (Harvard Architecture)
- Clock Speed: 10 MHz (Scaled down from 100 MHz via custom clock divider)
- Memory-Mapped I/O: *
Address 512: Physical Basys 3 Switches (Input)Address 256: Physical Basys 3 LEDs (Output)
- Instruction Support: Core ALU (ADD, SUB, AND, OR), Immediates (ADDI), Branching (BEQ, BNE), Memory (LW, SW), and Jumps (JAL, JALR).
This repository is divided into three distinct phases of hardware and software development:
(Task_A_Baseline_Countdown)
Demonstrates the baseline processor functionality before hardware upgrades.
- Application: A countdown timer that reads a seed value from the physical switches and decrements to zero on the LEDs.
- Software Delay Loop: Implements a nested delay loop utilizing strictly
BEQinstructions to achieve a human-readable 0.8-second cycle at 10 MHz. - Stack Management: Bypasses basic register storage by actively pushing the counter to Data Memory (initializing
spat address128), loading it, decrementing, and saving it back to the stack on every cycle to validate theLW/SWdatapaths.
(Task_B_Upgraded_CountUp)
Upgrades the physical Control Unit and datapath routing to support modular software execution.
- New Instructions: Engineered support for
JAL(Jump and Link),JALR(Jump and Link Register), andBNE(Branch if Not Equal). - Application: A Count-Up timer that isolates the counting logic into an independent subroutine, utilizing
JALto save the return address andJALRto return to the polling state. - Loop Optimization: Replaced clunky baseline
BEQloops with highly efficientBNEsoftware delay loops.
(Task_C_Fibonacci_Stack)
A final, general-purpose application stressing the upgraded processor limits.
- Application: Calculates and displays the Fibonacci sequence continuously.
-
Iterative Stack Architecture: Calculates the sequence not in registers, but by physically managing memory—pushing
$F_{n-1}$ and$F_{n-2}$ to the stack, popping them to the ALU for addition, and pushing the new sum back to RAM at 10 million cycles per second.
- Manual Branch Offset Calculation: All RISC-V B-type jump instructions were hand-calculated into exact 13-bit binary two's-complement formats to prevent Program Counter crashes and ensure flawless software loops.
- ALU Negative Immediate Fix: Identified and resolved a baseline architectural bug where I-type instructions with negative immediates (e.g.,
addi t2, t2, -1) defaulted to addition, fixed via directALUOpassignment in the Control Unit.
- Clone this repository to your local machine.
- Open Xilinx Vivado and create a new RTL Project for the Basys 3 board (Part:
xc7a35tcpg236-1). - Add the Verilog files from the specific Task folder you wish to test as Design Sources.
- Set
TopLevelProcessor.vas the Top module. - Generate Bitstream and program the device.
Muhammad Abdullah Asim Computer Science Student