# gunarirahuld-afk/5-stage-pipelined-risc-v-processor architecture

> Architecture diagram of the GitHub repository gunarirahuld-afk/5-stage-pipelined-risc-v-processor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor
- Repository: https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor

## Overview

This repository implements a 32-bit, five-stage pipelined RISC-V processor in Verilog. Its principal workflow fetches instructions, decodes them and reads operands, executes operations, accesses data memory, then writes results back to the register file. Pipeline registers separate the stages; forwarding and hazard detection address data dependencies. The graph follows the documented architecture and module descriptions; no RTL excerpts were provided, so detailed signal-level relationships are not asserted.

Main entry points: [`if_id.v`](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/if_id.v) (IF/ID Register), [`ex_mem.v`](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/ex_mem.v) (EX/MEM Register), [`mem_wb.v`](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/mem_wb.v) (MEM/WB Register), [`id_ex.v`](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/id_ex.v) (ID/EX Register)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_fetch["Instruction Fetch"]
  node_processor["Processor Top Level<br/>[riscv_5stage.v]"]
  node_pc["PC Logic<br/>[riscv_5stage.v]"]
  node_imem[("Instruction Memory")]
  node_ifid["IF/ID Register<br/>[if_id.v]"]
end

subgraph group_decode["Instruction Decode"]
  node_control["Control Unit<br/>[control_unit.v]"]
  node_regfile[("Register File<br/>[register_file.v]")]
  node_immediate["Immediate Generator"]
  node_idex["ID/EX Register<br/>[id_ex.v]"]
end

subgraph group_execute["Execute"]
  node_forward["Forwarding Unit<br/>[forwarding_unit.v]"]
  node_hazard["Hazard Detection<br/>[hazard_detection.v]"]
  node_alu["ALU<br/>[alu.v]"]
  node_exmem["EX/MEM Register<br/>[ex_mem.v]"]
end

subgraph group_memory["Memory Access"]
  node_dmem[("Data Memory<br/>[data_memory.v]")]
end

subgraph group_writeback["Write Back"]
  node_memwb["MEM/WB Register<br/>[mem_wb.v]"]
end

node_processor -->|"includes"| node_pc
node_pc -->|"selects instruction"| node_imem
node_imem -->|"feeds fetch stage"| node_ifid
node_ifid -->|"provides instruction"| node_control
node_ifid -->|"provides operands"| node_regfile
node_ifid -->|"provides instruction"| node_immediate
node_control -->|"passes controls"| node_idex
node_regfile -->|"passes operands"| node_idex
node_immediate -->|"passes immediate"| node_idex
node_idex -->|"provides operands"| node_alu
node_forward -->|"forwards results"| node_alu
node_hazard -->|"requests stalls"| node_processor
node_alu -->|"passes result"| node_exmem
node_exmem -->|"accesses data"| node_dmem
node_exmem -->|"passes result"| node_memwb
node_dmem -->|"passes load data"| node_memwb
node_memwb -->|"writes back"| node_regfile
node_exmem -->|"supplies later result"| node_forward
node_memwb -->|"supplies later result"| node_forward

click node_processor "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/riscv_5stage.v"
click node_pc "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/riscv_5stage.v"
click node_imem "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/instruction_memory.v"
click node_ifid "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/if_id.v"
click node_control "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/control_unit.v"
click node_regfile "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/register_file.v"
click node_immediate "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/immediate_generator.v"
click node_idex "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/id_ex.v"
click node_forward "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/forwarding_unit.v"
click node_hazard "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/hazard_detection.v"
click node_alu "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/alu.v"
click node_exmem "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/ex_mem.v"
click node_dmem "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/data_memory.v"
click node_memwb "https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/mem_wb.v"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_processor,node_pc,node_imem,node_ifid toneBlue
class node_control,node_regfile,node_immediate,node_idex toneAmber
class node_forward,node_hazard,node_alu,node_exmem toneMint
class node_dmem toneRose
class node_memwb toneIndigo
```

## Components

### Instruction Fetch

- [Processor Top Level](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/riscv_5stage.v): `riscv_5stage.v`
- [PC Logic](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/riscv_5stage.v): `riscv_5stage.v`
- [Instruction Memory](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/instruction_memory.v): `instruction_memory.v`
- [IF/ID Register](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/if_id.v): `if_id.v`

### Instruction Decode

- [Control Unit](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/control_unit.v): `control_unit.v`
- [Register File](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/register_file.v): `register_file.v`
- [Immediate Generator](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/immediate_generator.v): `immediate_generator.v`
- [ID/EX Register](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/id_ex.v): `id_ex.v`

### Execute

- [Forwarding Unit](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/forwarding_unit.v): `forwarding_unit.v`
- [Hazard Detection](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/hazard_detection.v): `hazard_detection.v`
- [ALU](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/alu.v): `alu.v`
- [EX/MEM Register](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/ex_mem.v): `ex_mem.v`

### Memory Access

- [Data Memory](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/data_memory.v): `data_memory.v`

### Write Back

- [MEM/WB Register](https://github.com/gunarirahuld-afk/5-stage-pipelined-risc-v-processor/blob/main/mem_wb.v): `mem_wb.v`

## Connections

- Processor Top Level → PC Logic: includes (evidence: `README.md`)
- PC Logic → Instruction Memory: selects instruction (evidence: `README.md`)
- Instruction Memory → IF/ID Register: feeds fetch stage (evidence: `README.md`)
- IF/ID Register → Control Unit: provides instruction (evidence: `README.md`)
- IF/ID Register → Register File: provides operands (evidence: `README.md`)
- IF/ID Register → Immediate Generator: provides instruction (evidence: `README.md`)
- Control Unit → ID/EX Register: passes controls (evidence: `README.md`)
- Register File → ID/EX Register: passes operands (evidence: `README.md`)
- Immediate Generator → ID/EX Register: passes immediate (evidence: `README.md`)
- ID/EX Register → ALU: provides operands (evidence: `README.md`)
- Forwarding Unit → ALU: forwards results (evidence: `README.md`)
- Hazard Detection → Processor Top Level: requests stalls (evidence: `README.md`)
- ALU → EX/MEM Register: passes result (evidence: `README.md`)
- EX/MEM Register → Data Memory: accesses data (evidence: `README.md`)
- EX/MEM Register → MEM/WB Register: passes result (evidence: `README.md`)
- Data Memory → MEM/WB Register: passes load data (evidence: `README.md`)
- MEM/WB Register → Register File: writes back (evidence: `README.md`)
- EX/MEM Register → Forwarding Unit: supplies later result (evidence: `README.md`)
- MEM/WB Register → Forwarding Unit: supplies later result (evidence: `README.md`)
