A Python toolchain (assembler, static analyzer, and simulator) for the SN/X architecture, a 16-bit educational RISC processor described in Naohiko Shimizu (清水尚彦)'s book コンピュータ設計の基礎知識.
- Complete SN/X instruction set — ADD, AND, SUB, SLT, NOT, SR, HLT, LD, ST, LDA, IN, OUT, BZ, BAL
- Data Initialization —
DWdirective for preloading Data Memory (DMEM) - Integrated static analysis — CFG, dataflow analysis, memory bounds checking, domain-sensitive label rules
- CLI + Python API — Use from command line or as a library
- snxasm compatible — Produces identical binary output to the original assembler
Option 1 — One-off execution (no install):
# via uv (recommended)
uvx --from snx-simulator snx sample.s
# via pipx
pipx run --spec snx-simulator snx sample.sOption 2 — Global install (recommended for CLI usage):
# via uv (recommended)
uv tool install snx-simulator
snx sample.s# via pipx
pipx install snx-simulator
snx sample.sOption 3 — Install via pip (for an existing Python environment / venv):
pip install snx-simulator
snx sample.smacOS / Linux:
curl -LsSf https://astral.sh/uv/install.sh | shWindows (PowerShell):
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"Install snx as a system-wide command:
uv tool install snx-simulatorOr from a local clone (for development):
git clone https://github.com/snowykr/snx-simulator.git
cd snx-simulator
uv tool install .If snx is not found after installation:
uv tool update-shellTo uninstall:
uv tool uninstall snx-simulatorInstall snx as a system-wide command:
pipx install snx-simulatorIf snx is not found after installation:
pipx ensurepathTo uninstall:
pipx uninstall snx-simulatorpip install snx-simulatorFor IDE integration or contributing:
git clone https://github.com/snowykr/snx-simulator.git
cd snx-simulator
uv syncThen run with:
uv run snx sample.sOr activate the virtual environment:
source .venv/bin/activate # Windows: .venv\Scripts\activate
snx sample.ssnx [-h] [-V] PATH
| Option | Description |
|---|---|
PATH |
Path to an SN/X assembly source file (.s) |
-h, --help |
Show help message |
-V, --version |
Show version number |
Examples:
snx sample.s
snx path/to/program.s
uv run snx sample.sThe CLI will:
- Parse and compile the assembly source
- Run static analysis (errors, warnings, and domain-sensitive label checks)
- If no errors, execute the program with preloaded
DWdata and display a trace table
from snx import compile_program, SNXSimulator
source = """
main:
LD $1, my_data
OUT $1
HLT
my_data:
DW 42
"""
result = compile_program(source)
if result.has_errors():
print(result.format_diagnostics())
raise SystemExit(1)
sim = SNXSimulator.from_compile_result(result)
sim.run()
print(f"Final registers: {sim.regs}")See Python API documentation for full reference.
| Document | Description |
|---|---|
| Architecture | SN/X processor specifications, instruction formats, ISA reference |
| Assembly Language | Syntax, grammar, operand types |
| Python API | Library usage, compile_program, SNXSimulator |
| Static Analysis | Diagnostic codes, CFG, dataflow analysis |
This project is open source. See the LICENSE file for details.