# omarzayedbeshir/cortex-m0-iss architecture

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

- Interactive diagram: https://gitdiagram.com/omarzayedbeshir/cortex-m0-iss
- Repository: https://github.com/omarzayedbeshir/cortex-m0-iss

## Overview

This repository is a Python Cortex-M0 Thumb instruction-set simulator. A user supplies a linked program’s readelf section dump to the CLI; it loads memory, resets the CPU from the vector table, and either disassembles .text or fetches and executes instructions. Execution dispatches decoded operations to arithmetic/control-flow and memory handlers, while SVC instructions provide guest I/O and process services. The CLI can also emit traces and reports faults or exit status. Edges follow the excerpts, SOURCE INDEX references, and README; unsampled implementation details are not inferred.

Main entry points: [`iss.py`](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/iss.py) (Simulator CLI), [`cpu.py`](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/cpu.py) (CPU state and dispatch), [`Memory.py`](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/Memory.py) (ROM and RAM), [`decoder.py`](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/decoder.py) (Thumb decoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and loading"]
  node_cli["Simulator CLI<br/>[iss.py]"]
end

subgraph group_engine["Instruction engine"]
  node_cpu["CPU state and dispatch<br/>[cpu.py]"]
  node_decoder["Thumb decoder<br/>[decoder.py]"]
  node_instruction["Instruction model<br/>[instruction.py]"]
  node_alu["ALU and branches<br/>[alu.py]"]
end

subgraph group_services["Memory and services"]
  node_memory[("ROM and RAM<br/>[Memory.py]")]
  node_svc["Core services<br/>[iss.py]"]
end

subgraph group_output["Disassembly and tracing"]
  node_disasm["Disassembly<br/>[iss.py]"]
  node_trace["Execution trace<br/>[iss.py]"]
end

node_user(("User"))
node_dump["Program dump"]
node_terminal["stdin stdout stderr"]

node_user -->|"runs"| node_cli
node_dump -->|"provides input"| node_cli
node_cli -->|"loads and resets"| node_memory
node_cli -->|"runs execution"| node_cpu
node_cpu -->|"dispatches operations"| node_alu
node_cpu -->|"dispatches memory ops"| node_memory
node_decoder -->|"creates instructions"| node_instruction
node_cpu -->|"dispatches by opcode"| node_instruction
node_cli -->|"decodes for disassembly"| node_decoder
node_cli -->|"prints disassembly"| node_disasm
node_cli -->|"handles SVC calls"| node_svc
node_svc -->|"reads guest memory"| node_memory
node_svc -->|"reads and writes"| node_terminal
node_cli -->|"writes optional trace"| node_trace
node_trace -->|"writes file"| node_terminal

click node_cli "https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/iss.py"
click node_memory "https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/Memory.py"
click node_cpu "https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/cpu.py"
click node_decoder "https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/decoder.py"
click node_instruction "https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/instruction.py"
click node_alu "https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/alu.py"
click node_svc "https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/iss.py"
click node_disasm "https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/iss.py"
click node_trace "https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/iss.py"

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_cli,node_user toneBlue
class node_cpu,node_decoder,node_instruction,node_alu toneAmber
class node_memory,node_svc toneMint
class node_disasm,node_trace toneRose
class node_dump,node_terminal toneIndigo
```

## Components

### CLI and loading

- [Simulator CLI](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/iss.py): `iss.py`

### Instruction engine

- [CPU state and dispatch](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/cpu.py): `cpu.py`
- [Thumb decoder](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/decoder.py): `decoder.py`
- [Instruction model](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/instruction.py): `instruction.py`
- [ALU and branches](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/alu.py): `alu.py`

### Memory and services

- [ROM and RAM](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/Memory.py): `Memory.py`
- [Core services](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/iss.py): `iss.py`

### Disassembly and tracing

- [Disassembly](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/iss.py): `iss.py`
- [Execution trace](https://github.com/omarzayedbeshir/cortex-m0-iss/blob/main/iss.py): `iss.py`

### Other components

- **User**
- **Program dump**
- **stdin stdout stderr**

## Connections

- User → Simulator CLI: runs (evidence: `README.md`)
- Program dump → Simulator CLI: provides input (evidence: `README.md`)
- Simulator CLI → ROM and RAM: loads and resets (evidence: `README.md`)
- Simulator CLI → CPU state and dispatch: runs execution (evidence: `README.md`)
- CPU state and dispatch → ALU and branches: dispatches operations (evidence: `cpu.py`)
- CPU state and dispatch → ROM and RAM: dispatches memory ops (evidence: `cpu.py`)
- Thumb decoder → Instruction model: creates instructions (evidence: `decoder.py`)
- CPU state and dispatch → Instruction model: dispatches by opcode (evidence: `cpu.py`)
- Simulator CLI → Thumb decoder: decodes for disassembly (evidence: `README.md`)
- Simulator CLI → Disassembly: prints disassembly (evidence: `README.md`)
- Simulator CLI → Core services: handles SVC calls (evidence: `iss.py`)
- Core services → ROM and RAM: reads guest memory (evidence: `iss.py`)
- Core services → stdin stdout stderr: reads and writes (evidence: `README.md`)
- Simulator CLI → Execution trace: writes optional trace (evidence: `README.md`)
- Execution trace → stdin stdout stderr: writes file (evidence: `README.md`)
