# matheusgerhard/risc-v-simulator architecture

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

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

## Overview

This browser-based RV32I teaching simulator turns Assembly or uploaded machine code into RAM contents, then runs instructions through a five-stage, multi-cycle processor while exposing its state. Its main path is assembly/upload → memory → clocked control unit → datapath and registers → visualized state and logs. The UI also offers processor selection and race comparison. The README documents several capabilities whose implementation was not sampled; those links are shown only where explicitly documented, and unsampled details are not inferred.

Main entry points: [`mac1/controlUnit.js`](https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/controlUnit.js) (RV32I Control Unit), [`src/pages/RaceComparison/index.jsx`](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/pages/RaceComparison/index.jsx) (Race Comparison), [`mac1/componentes/memory.js`](https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/componentes/memory.js) (Byte-Addressed RAM), [`src/App.jsx`](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/App.jsx) (App Shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Simulator UI"]
  node_app["App Shell<br/>[App.jsx]"]
  node_processor_choice["Active Processor<br/>[MacContext.jsx]"]
  node_instructions_ui["Assembly Editor<br/>[index.jsx]"]
  node_memory_ui["Memory Controls<br/>[index.jsx]"]
  node_binary_upload["Binary Upload<br/>[index.jsx]"]
  node_memory_views["Memory Views<br/>[index.jsx]"]
  node_sim_ui["Datapath Display<br/>[index.jsx]"]
  node_log_ui["Log Display<br/>[index.jsx]"]
end

subgraph group_assembly["Program Loading"]
  node_assembler["Two-Pass Assembler<br/>[montador.js]"]
  node_instruction_encoders["ISA Encoders<br/>[macroinstrucoes.js]"]
end

subgraph group_runtime["Processor Runtime"]
  node_ram[("Byte-Addressed RAM<br/>[memory.js]")]
  node_runner["Processor Instances<br/>[teste3.js]"]
  node_clock["Clock<br/>[clock.js]"]
  node_control["RV32I Control Unit<br/>[controlUnit.js]"]
  node_alu["ALU and Branches<br/>[alu.js]"]
  node_registers["Register Bank<br/>[registers.js]"]
  node_cache_d["Cache D Variant<br/>[controlUnit.js]"]
  node_cache_d_impl["Cache D Storage<br/>[cache.js]"]
  node_cache_a["Cache A Variant<br/>[controlUnit.js]"]
end

subgraph group_observability["Inspection and Comparison"]
  node_event_log["Execution Log<br/>[simulationLog.js]"]
  node_ips["IPS Measurement<br/>[useIPS.js]"]
  node_race["Race Comparison<br/>[index.jsx]"]
  node_race_track["Processor Track<br/>[ProcessorTrack.jsx]"]
  node_performance["Performance Tracker"]
end

node_user(("Learner"))

node_user -->|"opens"| node_app
node_app -->|"renders"| node_instructions_ui
node_app -->|"renders"| node_memory_ui
node_app -->|"renders"| node_sim_ui
node_app -->|"provides context"| node_processor_choice
node_user -->|"writes Assembly"| node_instructions_ui
node_instructions_ui -->|"submits program"| node_assembler
node_assembler -->|"encodes instructions"| node_instruction_encoders
node_assembler -->|"fills memory"| node_ram
node_user -->|"uploads binary"| node_binary_upload
node_binary_upload -->|"loads binary"| node_ram
node_memory_ui -->|"controls and reads"| node_ram
node_memory_ui -->|"starts execution"| node_runner
node_sim_ui -->|"observes processors"| node_runner
node_runner -->|"instantiates"| node_control
node_runner -->|"instantiates"| node_cache_d
node_runner -->|"instantiates"| node_cache_a
node_clock -->|"ticks stages"| node_control
node_control -->|"executes operations"| node_alu
node_control -->|"fetches and accesses"| node_ram
node_control -->|"reads and writes"| node_registers
node_control -->|"logs instructions"| node_event_log
node_ram -->|"logs writes"| node_event_log
node_memory_ui -->|"measures throughput"| node_ips
node_memory_views -->|"displays contents"| node_ram
node_log_ui -->|"subscribes to"| node_event_log
node_processor_choice -->|"selects processor"| node_sim_ui
node_cache_d -->|"extends"| node_control
node_cache_a -->|"extends"| node_control
node_race -->|"builds program"| node_assembler
node_race -->|"runs processor"| node_control
node_race -->|"runs variant"| node_cache_d
node_race -->|"runs variant"| node_cache_a
node_race -->|"updates metrics"| node_performance
node_race -->|"renders tracks"| node_race_track
node_cache_d -.->|"cache integration"| node_cache_d_impl

click node_app "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/App.jsx"
click node_processor_choice "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/context/MacContext.jsx"
click node_instructions_ui "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/instructions/index.jsx"
click node_memory_ui "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/memory/index.jsx"
click node_binary_upload "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/memory/BinaryUploader/index.jsx"
click node_memory_views "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/memory/memoryDisplay/index.jsx"
click node_assembler "https://github.com/matheusgerhard/risc-v-simulator/blob/main/montador/montador.js"
click node_instruction_encoders "https://github.com/matheusgerhard/risc-v-simulator/blob/main/montador/macroinstrucoes.js"
click node_ram "https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/componentes/memory.js"
click node_sim_ui "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/SImulation/index.jsx"
click node_runner "https://github.com/matheusgerhard/risc-v-simulator/blob/main/testes/teste3.js"
click node_clock "https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/componentes/clock.js"
click node_control "https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/controlUnit.js"
click node_alu "https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/componentes/alu.js"
click node_registers "https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/componentes/registers.js"
click node_cache_d "https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac2/controlUnit.js"
click node_cache_d_impl "https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac2/componentes/cache.js"
click node_cache_a "https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac3/controlUnit.js"
click node_event_log "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/services/simulationLog.js"
click node_log_ui "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/simulationLog/logDisplay/index.jsx"
click node_ips "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/hooks/useIPS.js"
click node_race "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/pages/RaceComparison/index.jsx"
click node_race_track "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/pages/RaceComparison/ProcessorTrack.jsx"
click node_performance "https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/services/performanceTracker.js"

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_app,node_processor_choice,node_instructions_ui,node_memory_ui,node_binary_upload,node_memory_views,node_sim_ui,node_log_ui toneBlue
class node_assembler,node_instruction_encoders toneAmber
class node_ram,node_runner,node_clock,node_control,node_alu,node_registers,node_cache_d,node_cache_d_impl,node_cache_a toneMint
class node_event_log,node_ips,node_race,node_race_track,node_performance toneRose
class node_user toneIndigo
```

## Components

### Simulator UI

- [App Shell](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/App.jsx): `src/App.jsx`
- [Active Processor](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/context/MacContext.jsx): `src/context/MacContext.jsx`
- [Assembly Editor](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/instructions/index.jsx): `src/components/instructions/index.jsx`
- [Memory Controls](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/memory/index.jsx): `src/components/memory/index.jsx`
- [Binary Upload](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/memory/BinaryUploader/index.jsx): `src/components/memory/BinaryUploader/index.jsx`
- [Memory Views](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/memory/memoryDisplay/index.jsx): `src/components/memory/memoryDisplay/index.jsx`
- [Datapath Display](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/SImulation/index.jsx): `src/components/SImulation/index.jsx`
- [Log Display](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/components/simulationLog/logDisplay/index.jsx): `src/components/simulationLog/logDisplay/index.jsx`

### Program Loading

- [Two-Pass Assembler](https://github.com/matheusgerhard/risc-v-simulator/blob/main/montador/montador.js): `montador/montador.js`
- [ISA Encoders](https://github.com/matheusgerhard/risc-v-simulator/blob/main/montador/macroinstrucoes.js): `montador/macroinstrucoes.js`

### Processor Runtime

- [Byte-Addressed RAM](https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/componentes/memory.js): `mac1/componentes/memory.js`
- [Processor Instances](https://github.com/matheusgerhard/risc-v-simulator/blob/main/testes/teste3.js): `testes/teste3.js`
- [Clock](https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/componentes/clock.js): `mac1/componentes/clock.js`
- [RV32I Control Unit](https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/controlUnit.js): `mac1/controlUnit.js`
- [ALU and Branches](https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/componentes/alu.js): `mac1/componentes/alu.js`
- [Register Bank](https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac1/componentes/registers.js): `mac1/componentes/registers.js`
- [Cache D Variant](https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac2/controlUnit.js): `mac2/controlUnit.js`
- [Cache D Storage](https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac2/componentes/cache.js): `mac2/componentes/cache.js`
- [Cache A Variant](https://github.com/matheusgerhard/risc-v-simulator/blob/main/mac3/controlUnit.js): `mac3/controlUnit.js`

### Inspection and Comparison

- [Execution Log](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/services/simulationLog.js): `src/services/simulationLog.js`
- [IPS Measurement](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/hooks/useIPS.js): `src/hooks/useIPS.js`
- [Race Comparison](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/pages/RaceComparison/index.jsx): `src/pages/RaceComparison/index.jsx`
- [Processor Track](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/pages/RaceComparison/ProcessorTrack.jsx): `src/pages/RaceComparison/ProcessorTrack.jsx`
- [Performance Tracker](https://github.com/matheusgerhard/risc-v-simulator/blob/main/src/services/performanceTracker.js): `src/services/performanceTracker.js`

### Other components

- **Learner**

## Connections

- Learner → App Shell: opens (evidence: `src/App.jsx`)
- App Shell → Assembly Editor: renders (evidence: `src/App.jsx`)
- App Shell → Memory Controls: renders (evidence: `src/App.jsx`)
- App Shell → Datapath Display: renders (evidence: `src/App.jsx`)
- App Shell → Active Processor: provides context (evidence: `src/App.jsx`)
- Learner → Assembly Editor: writes Assembly (evidence: `README.md`)
- Assembly Editor → Two-Pass Assembler: submits program (evidence: `README.md`)
- Two-Pass Assembler → ISA Encoders: encodes instructions (evidence: `montador/montador.js`)
- Two-Pass Assembler → Byte-Addressed RAM: fills memory (evidence: `README.md`)
- Learner → Binary Upload: uploads binary (evidence: `README.md`)
- Binary Upload → Byte-Addressed RAM: loads binary (evidence: `README.md`)
- Memory Controls → Byte-Addressed RAM: controls and reads (evidence: `src/components/memory/index.jsx`)
- Memory Controls → Processor Instances: starts execution (evidence: `src/components/memory/index.jsx`)
- Datapath Display → Processor Instances: observes processors (evidence: `src/components/SImulation/index.jsx`)
- Processor Instances → RV32I Control Unit: instantiates (evidence: `README.md`)
- Processor Instances → Cache D Variant: instantiates (evidence: `README.md`)
- Processor Instances → Cache A Variant: instantiates (evidence: `README.md`)
- Clock → RV32I Control Unit: ticks stages (evidence: `README.md`)
- RV32I Control Unit → ALU and Branches: executes operations (evidence: `mac1/controlUnit.js`)
- RV32I Control Unit → Byte-Addressed RAM: fetches and accesses (evidence: `README.md`)
- RV32I Control Unit → Register Bank: reads and writes (evidence: `README.md`)
- RV32I Control Unit → Execution Log: logs instructions (evidence: `mac1/controlUnit.js`)
- Byte-Addressed RAM → Execution Log: logs writes (evidence: `mac1/componentes/memory.js`)
- Memory Controls → IPS Measurement: measures throughput (evidence: `src/components/memory/index.jsx`)
- Memory Views → Byte-Addressed RAM: displays contents (evidence: `src/components/memory/memoryDisplay/index.jsx`)
- Log Display → Execution Log: subscribes to (evidence: `src/components/simulationLog/logDisplay/index.jsx`)
- Active Processor → Datapath Display: selects processor (evidence: `src/components/SImulation/index.jsx`)
- Cache D Variant → RV32I Control Unit: extends (evidence: `mac2/controlUnit.js`)
- Cache A Variant → RV32I Control Unit: extends (evidence: `mac3/controlUnit.js`)
- Race Comparison → Two-Pass Assembler: builds program (evidence: `src/pages/RaceComparison/index.jsx`)
- Race Comparison → RV32I Control Unit: runs processor (evidence: `src/pages/RaceComparison/index.jsx`)
- Race Comparison → Cache D Variant: runs variant (evidence: `src/pages/RaceComparison/index.jsx`)
- Race Comparison → Cache A Variant: runs variant (evidence: `src/pages/RaceComparison/index.jsx`)
- Race Comparison → Performance Tracker: updates metrics (evidence: `src/pages/RaceComparison/index.jsx`)
- Race Comparison → Processor Track: renders tracks (evidence: `src/pages/RaceComparison/index.jsx`)
- Cache D Variant → Cache D Storage: cache integration
