# tejasswat/rv32i-5stage-pipeline architecture

> Architecture diagram of the GitHub repository tejasswat/rv32i-5stage-pipeline, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tejasswat/rv32i-5stage-pipeline
- Repository: https://github.com/tejasswat/rv32i-5stage-pipeline

## Overview

This repository implements an educational five-stage RV32I pipelined CPU. Its documented workflow fetches sequential instructions, decodes operands and control, executes ALU operations, passes results through the structural MEM stage, and writes results back to the register file. The graph follows the documented pipeline and module roles; source excerpts were unavailable, so relationships are supported by Readme.md rather than inspected wiring. Hazard handling, data memory, loads/stores, branches, and jumps are explicitly out of scope.

Main entry points: [`srcs/id_ex_reg.v`](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/id_ex_reg.v) (ID/EX Register), [`srcs/if_id_reg.v`](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/if_id_reg.v) (IF/ID Register), [`srcs/regfile.v`](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/regfile.v) (Register File), [`srcs/alu.v`](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/alu.v) (ALU)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_fetch["Instruction Fetch"]
  node_pc["Program Counter<br/>[progr_counter.v]"]
  node_imem[("Instruction Memory<br/>[instr_mem.v]")]
  node_ifid["IF/ID Register<br/>[if_id_reg.v]"]
end

subgraph group_decode["Instruction Decode"]
  node_regfile[("Register File<br/>[regfile.v]")]
  node_immgen["Immediate Generator<br/>[imm_gen.v]"]
  node_control["Control Unit<br/>[control.v]"]
  node_idex["ID/EX Register<br/>[id_ex_reg.v]"]
end

subgraph group_execute["Execute"]
  node_alucontrol["ALU Control<br/>[alu_control.v]"]
  node_alu["ALU<br/>[alu.v]"]
end

subgraph group_memory["Memory Stage"]
  node_exmem["EX/MEM Register<br/>[ex_mem_reg.v]"]
  node_memstage["MEM Pass-through<br/>[ex_mem_reg.v]"]
end

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

node_cpu["CPU Top<br/>[cpu_top.v]"]

node_pc -->|"selects instruction"| node_imem
node_imem -->|"passes instruction"| node_ifid
node_ifid -->|"provides fields"| node_regfile
node_ifid -->|"provides immediate"| node_immgen
node_ifid -->|"provides opcode"| node_control
node_regfile -->|"passes operands"| node_idex
node_immgen -->|"passes immediate"| node_idex
node_control -->|"pipelines controls"| node_idex
node_idex -->|"provides operation"| node_alucontrol
node_idex -->|"provides operands"| node_alu
node_alucontrol -->|"selects operation"| node_alu
node_alu -->|"passes result"| node_exmem
node_exmem -->|"feeds pass-through"| node_memstage
node_memstage -->|"passes result"| node_memwb
node_memwb -->|"writes result"| node_regfile

click node_cpu "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/cpu_top.v"
click node_pc "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/progr_counter.v"
click node_imem "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/instr_mem.v"
click node_ifid "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/if_id_reg.v"
click node_regfile "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/regfile.v"
click node_immgen "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/imm_gen.v"
click node_control "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/control.v"
click node_idex "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/id_ex_reg.v"
click node_alucontrol "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/alu_control.v"
click node_alu "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/alu.v"
click node_exmem "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/ex_mem_reg.v"
click node_memstage "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/ex_mem_reg.v"
click node_memwb "https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/mem_wb_reg.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_pc,node_imem,node_ifid toneBlue
class node_regfile,node_immgen,node_control,node_idex toneAmber
class node_alucontrol,node_alu toneMint
class node_exmem,node_memstage toneRose
class node_memwb toneIndigo
class node_cpu toneTeal
```

## Components

### Instruction Fetch

- [Program Counter](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/progr_counter.v): `srcs/progr_counter.v`
- [Instruction Memory](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/instr_mem.v): `srcs/instr_mem.v`
- [IF/ID Register](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/if_id_reg.v): `srcs/if_id_reg.v`

### Instruction Decode

- [Register File](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/regfile.v): `srcs/regfile.v`
- [Immediate Generator](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/imm_gen.v): `srcs/imm_gen.v`
- [Control Unit](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/control.v): `srcs/control.v`
- [ID/EX Register](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/id_ex_reg.v): `srcs/id_ex_reg.v`

### Execute

- [ALU Control](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/alu_control.v): `srcs/alu_control.v`
- [ALU](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/alu.v): `srcs/alu.v`

### Memory Stage

- [EX/MEM Register](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/ex_mem_reg.v): `srcs/ex_mem_reg.v`
- [MEM Pass-through](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/ex_mem_reg.v): `srcs/ex_mem_reg.v`

### Write Back

- [MEM/WB Register](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/mem_wb_reg.v): `srcs/mem_wb_reg.v`

### Other components

- [CPU Top](https://github.com/tejasswat/rv32i-5stage-pipeline/blob/main/srcs/cpu_top.v): `srcs/cpu_top.v`

## Connections

- Program Counter → Instruction Memory: selects instruction (evidence: `Readme.md`)
- Instruction Memory → IF/ID Register: passes instruction (evidence: `Readme.md`)
- IF/ID Register → Register File: provides fields (evidence: `Readme.md`)
- IF/ID Register → Immediate Generator: provides immediate (evidence: `Readme.md`)
- IF/ID Register → Control Unit: provides opcode (evidence: `Readme.md`)
- Register File → ID/EX Register: passes operands (evidence: `Readme.md`)
- Immediate Generator → ID/EX Register: passes immediate (evidence: `Readme.md`)
- Control Unit → ID/EX Register: pipelines controls (evidence: `Readme.md`)
- ID/EX Register → ALU Control: provides operation (evidence: `Readme.md`)
- ID/EX Register → ALU: provides operands (evidence: `Readme.md`)
- ALU Control → ALU: selects operation (evidence: `Readme.md`)
- ALU → EX/MEM Register: passes result (evidence: `Readme.md`)
- EX/MEM Register → MEM Pass-through: feeds pass-through (evidence: `Readme.md`)
- MEM Pass-through → MEM/WB Register: passes result (evidence: `Readme.md`)
- MEM/WB Register → Register File: writes result (evidence: `Readme.md`)
