# abhinavtiwari32/risc-v architecture

> Architecture diagram of the GitHub repository abhinavtiwari32/risc-v, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhinavtiwari32/risc-v
- Repository: https://github.com/abhinavtiwari32/risc-v

## Overview

##### Project type and purpose
- This is a hardware‐design project: a 32-bit RISC-V processor implementing a pipelined datapath in Verilog.
- Its purpose is to fetch, decode, execute, access memory, and write back RISC-V instructions in hardware, including forwarding logic.

##### File structure
- Top-level files:
- RISCV_TOP.v            – the top-level wrapper that instantiates and wires together all submodules
- RISC_V_tb.v            – testbench for functional verification
- inst.hex               – instruction memory contents
- Compute units and helpers:
- ALU.v, ALU_Control.v, AND_logic.v, ImmGen.v, Mux.v, 3_to_1_mux.v
- Pipeline registers:
- IFID_Reg.v, IDEXE_Reg.v, EXMEM_Reg.v, MEMWB_Reg.v
- Control and hazard units:
- Control_Unit.v, Forwarding_unit.v
- Memories and register file:
- Instruction_Memory.v, Data_Memory.v, Program_Counter.v, PCplus4.v, Register_File.v
- Simulation artifacts (.vcd, .out) and configuration (inst.hex)

##### Key insights from the README
- Confirms a 32-bit single-cycle RISC-V architecture, though the presence of pipeline registers and a forwarding unit indicates a pipelined implementation.

a. Main components to show as blocks
1. Instruction Fetch Stage
– Program Counter (PC)
– PCplus4 unit
– Instruction Memory
– IF/ID pipeline register
2. Instruction Decode Stage
– Register File
– Immediate Generator
– Control Unit
– Hazard detection/Forwarding Unit inputs (for control signals)
– ID/EX pipeline register
3. Execute Stage
– ALU (with inputs from muxes and ALU Control)
– ALU Control submodule
– MUXes for selecting register/immediate/forwarded operands
– EX/MEM pipeline register
4. Memory Stage
– Data Memory
– EX/MEM outputs feeding memory address/data
– MEM/WB pipeline register
5. Write-Back Stage
– MUX selecting memory data vs. ALU result
– Register File write port
b. Relationships and data/control flow
– Overlay control paths: Control Unit outputs go to mux select lines, memory enable, reg file write enable.
– Show forwarding unit tapping EX/MEM and MEM/WB outputs back to mux inputs in the Execute stage.
c. Architectural patterns and design principles
– Five-stage pipeline (IF, ID, EX, MEM, WB)
– Hazard mitigation through forwarding
– Single instruction per cycle throughput after pipeline fill
d. Technologies, frameworks, libraries
– Verilog modules, hierarchical instantiation
– Testbench for functional verification (likely run with Icarus/ModelSim)
– inst.hex used to initialize instruction memory

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Instruction Fetch Stage
    subgraph "Instruction Fetch (IF)"
        direction TB
        PC["Program Counter"]:::state
        PC4["PCplus4"]:::comb
        IMem["Instruction Memory"]:::memory
        IFID["IF/ID Register"]:::pipeline
    end

    %% Instruction Decode Stage
    subgraph "Instruction Decode (ID)"
        direction TB
        RF["Register File"]:::state
        Imm["Immediate Generator"]:::comb
        Ctrl["Control Unit"]:::control
        FU["Forwarding Unit"]:::control
        IDEX["ID/EX Register"]:::pipeline
    end

    %% Execute Stage
    subgraph "Execute (EX)"
        direction TB
        ALUC["ALU Control"]:::comb
        D1Mux["MUX (Reg/Imm)"]:::comb
        D2Mux["3-to-1 MUX"]:::comb
        AND["AND Logic"]:::comb
        ALU["ALU"]:::comb
        EXMEM["EX/MEM Register"]:::pipeline
    end

    %% Memory Stage
    subgraph "Memory (MEM)"
        direction TB
        DMem["Data Memory"]:::memory
        MEMWB["MEM/WB Register"]:::pipeline
    end

    %% Write-Back Stage
    subgraph "Write-Back (WB)"
        direction TB
        WB_Mux["MUX (ALU/Memory)"]:::comb
        RF_Write["Register File Write Port"]:::state
    end

    %% Top-Level and Testbench
    subgraph "Top-Level"
        direction TB
        TOP["RISCV_TOP"]:::top
        TB["RISC_V_tb"]:::test
        InstHex["inst.hex"]:::config
    end

    %% Data Path Connections
    PC --> PC4
    PC4 --> IMem
    IMem --> IFID
    IFID --> RF
    IFID --> Ctrl
    RF --> D1Mux
    Imm --> D1Mux
    IFID --> Imm
    Ctrl --> D1Mux
    Ctrl --> D2Mux
    IFID --> FU
    IFID --> IDEX
    D1Mux --> ALU
    D2Mux --> ALU
    ALUC --> ALU
    ALU --> EXMEM
    EXMEM --> DMem
    DMem --> MEMWB
    MEMWB --> WB_Mux
    WB_Mux --> RF_Write

    %% Control Signals
    Ctrl -->|"ALUOp, MemRead, MemWrite, RegWrite, Branch"| ALU
    Ctrl -->|"MemToReg select"| WB_Mux

    %% Forwarding Paths
    EXMEM -->|"E-stage result"| D2Mux
    MEMWB -->|"W-stage result"| D2Mux

    %% Hazard Unit Inputs
    EXMEM --> FU
    MEMWB --> FU
    FU --> D2Mux

    %% Top-Level Instantiation
    TOP --> PC
    TOP --> IMem
    TOP --> RF
    TOP --> ALU
    TOP --> DMem
    TOP --> TB
    TOP --> InstHex

    %% Click Events
    click PC "https://github.com/abhinavtiwari32/risc-v/blob/main/Program_Counter.v"
    click PC4 "https://github.com/abhinavtiwari32/risc-v/blob/main/PCplus4.v"
    click IMem "https://github.com/abhinavtiwari32/risc-v/blob/main/Instruction_Memory.v"
    click IFID "https://github.com/abhinavtiwari32/risc-v/blob/main/IFID_Reg.v"
    click RF "https://github.com/abhinavtiwari32/risc-v/blob/main/Register_File.v"
    click Imm "https://github.com/abhinavtiwari32/risc-v/blob/main/ImmGen.v"
    click Ctrl "https://github.com/abhinavtiwari32/risc-v/blob/main/Control_Unit.v"
    click FU "https://github.com/abhinavtiwari32/risc-v/blob/main/Forwarding_unit.v"
    click IDEX "https://github.com/abhinavtiwari32/risc-v/blob/main/IDEXE_Reg.v"
    click ALU "https://github.com/abhinavtiwari32/risc-v/blob/main/ALU.v"
    click ALUC "https://github.com/abhinavtiwari32/risc-v/blob/main/ALU_Control.v"
    click D1Mux "https://github.com/abhinavtiwari32/risc-v/blob/main/Mux.v"
    click D2Mux "https://github.com/abhinavtiwari32/risc-v/blob/main/3_to_1_mux.v"
    click AND "https://github.com/abhinavtiwari32/risc-v/blob/main/AND_logic.v"
    click EXMEM "https://github.com/abhinavtiwari32/risc-v/blob/main/EXMEM_Reg.v"
    click DMem "https://github.com/abhinavtiwari32/risc-v/blob/main/Data_Memory.v"
    click MEMWB "https://github.com/abhinavtiwari32/risc-v/blob/main/MEMWB_Reg.v"
    click TOP "https://github.com/abhinavtiwari32/risc-v/blob/main/RISCV_TOP.v"
    click TB "https://github.com/abhinavtiwari32/risc-v/blob/main/RISC_V_tb.v"
    click InstHex "https://github.com/abhinavtiwari32/risc-v/blob/main/inst.hex"

    %% Styles
    classDef comb fill:#e0ffe0,stroke:#2e8b57
    classDef pipeline fill:#e0f0ff,stroke:#1f4e79
    classDef memory fill:#fff0b3,stroke:#b8860b
    classDef state fill:#ffe0e0,stroke:#8b0000
    classDef control fill:#ffe6f0,stroke:#c71585
    classDef top fill:#d3d3d3,stroke:#696969
    classDef test fill:#f0e68c,stroke:#bdb76b
    classDef config fill:#fafad2,stroke:#aaa
```
