# raghavtandonn/e20simulator architecture

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

- Interactive diagram: https://gitdiagram.com/raghavtandonn/e20simulator
- Repository: https://github.com/raghavtandonn/e20simulator
- Video tour (about a minute): https://gitdiagram.com/raghavtandonn/e20simulator/video

## Overview

E20 Simulator is a command-line machine-code runner: a user supplies a .bin file, the program loads it into simulated memory, executes instructions against CPU state, and prints the final PC, registers, and first 128 memory words. The single-file design combines loading, execution, instruction dispatch, state updates, and output. The excerpts show the main call sequence and representative dispatch and instruction behavior; some implementation details are omitted.

Main entry points: [`sim.cpp`](https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp) (State printer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Program input"]
  node_entry["CLI entry<br/>[sim.cpp]"]
  node_loader["Code loader<br/>[sim.cpp]"]
end

subgraph group_execution["CPU execution"]
  node_image[("Machine memory<br/>[sim.cpp]")]
  node_runner["Execution loop<br/>[sim.cpp]"]
  node_decode["Instruction decode<br/>[sim.cpp]"]
  node_dispatch["Opcode dispatch<br/>[sim.cpp]"]
  node_handlers["Instruction handlers<br/>[sim.cpp]"]
  node_registers[("Registers<br/>[sim.cpp]")]
  node_pc["Program counter<br/>[sim.cpp]"]
end

subgraph group_result["Final state"]
  node_printer["State printer<br/>[sim.cpp]"]
end

node_user(("User"))
node_terminal(("Console output"))

node_user -->|"runs"| node_entry
node_entry -->|"loads file"| node_loader
node_loader -->|"writes words"| node_image
node_entry -->|"starts simulation"| node_runner
node_runner -->|"fetches instruction"| node_image
node_runner -->|"executes instruction"| node_decode
node_decode -->|"routes opcode"| node_dispatch
node_dispatch -->|"calls handler"| node_handlers
node_handlers -->|"reads or writes"| node_image
node_handlers -->|"reads or writes"| node_registers
node_handlers -->|"updates"| node_pc
node_entry -->|"prints final state"| node_printer
node_printer -->|"reads"| node_registers
node_printer -->|"reads"| node_image
node_printer -->|"reads"| node_pc
node_printer -->|"writes output"| node_terminal

click node_entry "https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp"
click node_loader "https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp"
click node_image "https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp"
click node_runner "https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp"
click node_decode "https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp"
click node_dispatch "https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp"
click node_handlers "https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp"
click node_registers "https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp"
click node_pc "https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp"
click node_printer "https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp"

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_entry,node_loader,node_user toneBlue
class node_image,node_runner,node_decode,node_dispatch,node_handlers,node_registers,node_pc toneAmber
class node_printer toneMint
class node_terminal toneIndigo
```

## Components

### Program input

- [CLI entry](https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp): `sim.cpp`
- [Code loader](https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp): `sim.cpp`

### CPU execution

- [Machine memory](https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp): `sim.cpp`
- [Execution loop](https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp): `sim.cpp`
- [Instruction decode](https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp): `sim.cpp`
- [Opcode dispatch](https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp): `sim.cpp`
- [Instruction handlers](https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp): `sim.cpp`
- [Registers](https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp): `sim.cpp`
- [Program counter](https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp): `sim.cpp`

### Final state

- [State printer](https://github.com/raghavtandonn/e20simulator/blob/main/sim.cpp): `sim.cpp`

### Other components

- **User**
- **Console output**

## Connections

- User → CLI entry: runs
- CLI entry → Code loader: loads file
- Code loader → Machine memory: writes words
- CLI entry → Execution loop: starts simulation
- Execution loop → Machine memory: fetches instruction
- Execution loop → Instruction decode: executes instruction
- Instruction decode → Opcode dispatch: routes opcode
- Opcode dispatch → Instruction handlers: calls handler
- Instruction handlers → Machine memory: reads or writes
- Instruction handlers → Registers: reads or writes
- Instruction handlers → Program counter: updates
- CLI entry → State printer: prints final state
- State printer → Registers: reads
- State printer → Machine memory: reads
- State printer → Program counter: reads
- State printer → Console output: writes output
