# sweetiecloud/risc_cpu architecture

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

- Interactive diagram: https://gitdiagram.com/sweetiecloud/risc_cpu
- Repository: https://github.com/sweetiecloud/risc_cpu

## Overview

This repository implements a 32-bit RISC processor in Verilog. Its documented control flow is an eight-step fetch–decode–execute–store FSM, supporting eight instructions; the datapath includes an ALU, program counter, accumulator register, memory, and address mux. The README identifies these as the system’s RTL blocks but does not show their wiring, so the graph captures only that documented integration and the stated FSM stage order. Testbenches and FPGA constraints are omitted as development artifacts.

Main entry points: [`sources/risc_cpu.v`](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/risc_cpu.v) (RISC CPU), [`sources/controller.v`](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/controller.v) (FSM controller), [`sources/alu.v`](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/alu.v) (ALU), [`sources/pc.v`](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/pc.v) (Program counter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Control flow"]
  node_controller["FSM controller<br/>[controller.v]"]
  node_fetch["Fetch<br/>[controller.v]"]
  node_decode["Decode<br/>[controller.v]"]
  node_execute["Execute<br/>[controller.v]"]
  node_store["Store<br/>[controller.v]"]
end

subgraph group_datapath["Datapath"]
  node_cpu["RISC CPU<br/>[risc_cpu.v]"]
  node_alu["ALU<br/>[alu.v]"]
  node_pc["Program counter<br/>[pc.v]"]
  node_address_mux["Address mux<br/>[address_mux.v]"]
end

subgraph group_storage["State and memory"]
  node_register["Accumulator register<br/>[register.v]"]
  node_memory[("32-word memory<br/>[memory.v]")]
end

node_cpu -->|"integrates"| node_controller
node_cpu -->|"integrates"| node_alu
node_cpu -->|"integrates"| node_pc
node_cpu -->|"integrates"| node_address_mux
node_cpu -->|"integrates"| node_register
node_cpu -->|"integrates"| node_memory
node_controller -->|"sequences"| node_fetch
node_fetch -->|"then"| node_decode
node_decode -->|"then"| node_execute
node_execute -->|"then"| node_store

click node_cpu "https://github.com/sweetiecloud/risc_cpu/blob/main/sources/risc_cpu.v"
click node_controller "https://github.com/sweetiecloud/risc_cpu/blob/main/sources/controller.v"
click node_fetch "https://github.com/sweetiecloud/risc_cpu/blob/main/sources/controller.v"
click node_decode "https://github.com/sweetiecloud/risc_cpu/blob/main/sources/controller.v"
click node_execute "https://github.com/sweetiecloud/risc_cpu/blob/main/sources/controller.v"
click node_store "https://github.com/sweetiecloud/risc_cpu/blob/main/sources/controller.v"
click node_alu "https://github.com/sweetiecloud/risc_cpu/blob/main/sources/alu.v"
click node_pc "https://github.com/sweetiecloud/risc_cpu/blob/main/sources/pc.v"
click node_address_mux "https://github.com/sweetiecloud/risc_cpu/blob/main/sources/address_mux.v"
click node_register "https://github.com/sweetiecloud/risc_cpu/blob/main/sources/register.v"
click node_memory "https://github.com/sweetiecloud/risc_cpu/blob/main/sources/memory.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_controller,node_fetch,node_decode,node_execute,node_store toneBlue
class node_cpu,node_alu,node_pc,node_address_mux toneAmber
class node_register,node_memory toneMint
```

## Components

### Control flow

- [FSM controller](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/controller.v): `sources/controller.v`
- [Fetch](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/controller.v): `sources/controller.v`
- [Decode](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/controller.v): `sources/controller.v`
- [Execute](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/controller.v): `sources/controller.v`
- [Store](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/controller.v): `sources/controller.v`

### Datapath

- [RISC CPU](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/risc_cpu.v): `sources/risc_cpu.v`
- [ALU](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/alu.v): `sources/alu.v`
- [Program counter](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/pc.v): `sources/pc.v`
- [Address mux](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/address_mux.v): `sources/address_mux.v`

### State and memory

- [Accumulator register](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/register.v): `sources/register.v`
- [32-word memory](https://github.com/sweetiecloud/risc_cpu/blob/main/sources/memory.v): `sources/memory.v`

## Connections

- RISC CPU → FSM controller: integrates (evidence: `README.md`)
- RISC CPU → ALU: integrates (evidence: `README.md`)
- RISC CPU → Program counter: integrates (evidence: `README.md`)
- RISC CPU → Address mux: integrates (evidence: `README.md`)
- RISC CPU → Accumulator register: integrates (evidence: `README.md`)
- RISC CPU → 32-word memory: integrates (evidence: `README.md`)
- FSM controller → Fetch: sequences (evidence: `README.md`)
- Fetch → Decode: then (evidence: `README.md`)
- Decode → Execute: then (evidence: `README.md`)
- Execute → Store: then (evidence: `README.md`)
