# gzhy5111/cpu architecture

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

- Interactive diagram: https://gitdiagram.com/gzhy5111/cpu
- Repository: https://github.com/gzhy5111/cpu

## Overview

This repository is an incremental Verilog implementation of a MIPS CPU, with chapter directories recording successive feature additions. The documented workflow advances an instruction through fetch, decode, execute, and memory access; later versions add forwarding, arithmetic, HI/LO operations, pipeline stalls, and multi-cycle multiplication and division. The graph uses the latest relevant chapter paths as representative implementations. Source excerpts were unavailable, so edges are limited to relationships stated in the README; detailed module wiring is not verified.

Main entry points: [`codes/Chapter7_3/ex.v`](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/ex.v) (Execute), [`codes/Chapter7_3/openmips.v`](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/openmips.v) (OpenMIPS Core), [`codes/Chapter7_3/id.v`](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/id.v) (Decode), [`codes/Chapter7_3/div.v`](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/div.v) (Division Unit)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["CPU Pipeline"]
  node_fetch["Fetch<br/>[pc_reg.v]"]
  node_decode["Decode<br/>[id.v]"]
  node_execute["Execute<br/>[ex.v]"]
  node_memory["Memory Stage<br/>[mem.v]"]
  node_forwarding["Data Forwarding<br/>[ex.v]"]
  node_stall["Pipeline Stall<br/>[ctrl.v]"]
  node_cpu["OpenMIPS Core<br/>[openmips.v]"]
end

subgraph group_state["CPU State"]
  node_registers["Register File<br/>[regfile.v]"]
  node_hilo["HI/LO Registers<br/>[hilo_reg.v]"]
end

subgraph group_arithmetic["Arithmetic Features"]
  node_alu["Integer Arithmetic<br/>[ex.v]"]
  node_divider["Division Unit<br/>[div.v]"]
  node_divcontrol["Division Control<br/>[div_fsm.v]"]
end

subgraph group_program["Instruction Programs"]
  node_programs["MIPS Programs"]
  node_rom["Instruction ROM<br/>[inst_rom.v]"]
end

node_author(("CPU Author"))

node_author -->|"writes programs"| node_programs
node_fetch -->|"fetch then decode"| node_decode
node_decode -->|"decode then execute"| node_execute
node_execute -->|"execute then access"| node_memory
node_programs -.->|"assemble for ROM"| node_rom
node_cpu -->|"uses forwarding"| node_forwarding
node_cpu -->|"uses stalls"| node_stall
node_execute -->|"uses HI/LO"| node_hilo
node_execute -->|"performs division"| node_divider
node_divider -.->|"multi-cycle control"| node_divcontrol

click node_fetch "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/pc_reg.v"
click node_decode "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/id.v"
click node_execute "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/ex.v"
click node_memory "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/mem.v"
click node_forwarding "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter5/ex.v"
click node_stall "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_1/ctrl.v"
click node_cpu "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/openmips.v"
click node_registers "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/regfile.v"
click node_hilo "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/hilo_reg.v"
click node_alu "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/ex.v"
click node_divider "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/div.v"
click node_divcontrol "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/div_fsm.v"
click node_programs "https://github.com/gzhy5111/cpu/tree/master/codes/Chapter7_3/AsmCode"
click node_rom "https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/inst_rom.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_fetch,node_decode,node_execute,node_memory,node_forwarding,node_stall,node_cpu toneBlue
class node_registers,node_hilo toneAmber
class node_alu,node_divider,node_divcontrol toneMint
class node_programs,node_rom toneRose
class node_author toneIndigo
```

## Components

### CPU Pipeline

- [Fetch](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/pc_reg.v): `codes/Chapter7_3/pc_reg.v`
- [Decode](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/id.v): `codes/Chapter7_3/id.v`
- [Execute](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/ex.v): `codes/Chapter7_3/ex.v`
- [Memory Stage](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/mem.v): `codes/Chapter7_3/mem.v`
- [Data Forwarding](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter5/ex.v): `codes/Chapter5/ex.v`
- [Pipeline Stall](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_1/ctrl.v): `codes/Chapter7_1/ctrl.v`
- [OpenMIPS Core](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/openmips.v): `codes/Chapter7_3/openmips.v`

### CPU State

- [Register File](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/regfile.v): `codes/Chapter7_3/regfile.v`
- [HI/LO Registers](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/hilo_reg.v): `codes/Chapter7_3/hilo_reg.v`

### Arithmetic Features

- [Integer Arithmetic](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/ex.v): `codes/Chapter7_3/ex.v`
- [Division Unit](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/div.v): `codes/Chapter7_3/div.v`
- [Division Control](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/div_fsm.v): `codes/Chapter7_3/div_fsm.v`

### Instruction Programs

- [MIPS Programs](https://github.com/gzhy5111/cpu/tree/master/codes/Chapter7_3/AsmCode): `codes/Chapter7_3/AsmCode`
- [Instruction ROM](https://github.com/gzhy5111/cpu/blob/master/codes/Chapter7_3/inst_rom.v): `codes/Chapter7_3/inst_rom.v`

### Other components

- **CPU Author**

## Connections

- CPU Author → MIPS Programs: writes programs (evidence: `README.md`)
- Fetch → Decode: fetch then decode (evidence: `README.md`)
- Decode → Execute: decode then execute (evidence: `README.md`)
- Execute → Memory Stage: execute then access (evidence: `README.md`)
- MIPS Programs → Instruction ROM: assemble for ROM
- OpenMIPS Core → Data Forwarding: uses forwarding (evidence: `README.md`)
- OpenMIPS Core → Pipeline Stall: uses stalls (evidence: `README.md`)
- Execute → HI/LO Registers: uses HI/LO (evidence: `README.md`)
- Execute → Division Unit: performs division (evidence: `README.md`)
- Division Unit → Division Control: multi-cycle control
