# ksbharadwaj148-wq/hack_assembly architecture

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

- Interactive diagram: https://gitdiagram.com/ksbharadwaj148-wq/hack_assembly
- Repository: https://github.com/ksbharadwaj148-wq/hack_assembly

## Overview

Hack_assembler converts Hack assembly text into binary machine-code files. The workflow starts with a user supplying an .asm path, then the CLI reads it, the assembler parses commands in two passes, resolves labels and variables through a symbol table, encodes instructions, and writes the .hack result. The README describes this conversion; the graph focuses on the inspected runtime modules and their evidenced calls.

Main entry points: [`assembler.py`](https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/assembler.py) (Two-pass assembler), [`parser.py`](https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/parser.py) (Command parser), [`symbol_table.py`](https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/symbol_table.py) (Symbol table), [`code.py`](https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/code.py) (Mnemonic encoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_assembly["Assembly conversion"]
  node_cli["CLI entry<br/>[assembler.py]"]
  node_assembler["Two-pass assembler<br/>[assembler.py]"]
  node_parser["Command parser<br/>[parser.py]"]
  node_symbols[("Symbol table<br/>[symbol_table.py]")]
end

subgraph group_encoding["Instruction encoding"]
  node_encoder["Mnemonic encoder<br/>[code.py]"]
end

node_user(("Assembly user"))
node_hackfile["Hack output"]

node_user -->|"supplies ASM path"| node_cli
node_cli -->|"invokes assembly"| node_assembler
node_assembler -->|"parses commands"| node_parser
node_assembler -->|"resolves symbols"| node_symbols
node_assembler -->|"encodes mnemonics"| node_encoder
node_assembler -->|"writes machine code"| node_hackfile

click node_cli "https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/assembler.py"
click node_assembler "https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/assembler.py"
click node_parser "https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/parser.py"
click node_symbols "https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/symbol_table.py"
click node_encoder "https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/code.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_assembler,node_parser,node_symbols,node_user toneBlue
class node_encoder toneAmber
class node_hackfile toneIndigo
```

## Components

### Assembly conversion

- [CLI entry](https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/assembler.py): `assembler.py`
- [Two-pass assembler](https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/assembler.py): `assembler.py`
- [Command parser](https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/parser.py): `parser.py`
- [Symbol table](https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/symbol_table.py): `symbol_table.py`

### Instruction encoding

- [Mnemonic encoder](https://github.com/ksbharadwaj148-wq/hack_assembly/blob/main/code.py): `code.py`

### Other components

- **Assembly user**
- **Hack output**

## Connections

- Assembly user → CLI entry: supplies ASM path (evidence: `README.md`)
- CLI entry → Two-pass assembler: invokes assembly (evidence: `assembler.py`)
- Two-pass assembler → Command parser: parses commands (evidence: `assembler.py`)
- Two-pass assembler → Symbol table: resolves symbols (evidence: `assembler.py`)
- Two-pass assembler → Mnemonic encoder: encodes mnemonics (evidence: `assembler.py`)
- Two-pass assembler → Hack output: writes machine code (evidence: `assembler.py`)
