Add Verilog RTL, simulators, and toolchain#2
Open
Elwimen wants to merge 4 commits intoDanijel-Korent:mainfrom
Open
Add Verilog RTL, simulators, and toolchain#2Elwimen wants to merge 4 commits intoDanijel-Korent:mainfrom
Elwimen wants to merge 4 commits intoDanijel-Korent:mainfrom
Conversation
Two-pass assembler that takes .asm source files and outputs Logisim v2.0 raw hex format. Supports labels, comments, hex/decimal/char literals (including escape sequences like '\n'). Also adds a clean, labelled assembly source for useless_OS that assembles identically to the existing useless_OS.hex. This was made quickly by Claude Sonnet 4.6 as a proof of concept. AI building stuff
assembler.py: - String literals: mov out1, "Hello\nWorld" expands to per-char movs - Numeric labels: disassembler output (0x0:, 0xa:) now assembles cleanly Makefile: - make / make all: force-rebuild all *.asm -> *.hex - make <stem>: assemble <stem>.asm into useless_OS.hex (active ROM) New sources: - useless_OS_strings.asm: useless_OS rewritten using string literals - fake_linux.asm: fake Linux boot + POSIX-like shell (ls, pwd, uname, whoami, help, exit); exit uses out2=0xFF as halt signal
- verilog/cpu.v: cycle-accurate single-cycle RTL (Harvard, 8-bit, 13 instructions, NAND-only ALU) - verilog/tb_cpu.v: automated testbench — injects "help\n", captures TTY output, dumps VCD waveform - verilog/tb_interactive.v: interactive testbench via Icarus $fgetc; exit with Ctrl-D - verilog/Makefile: make sim / make isim / make wave / make clean - cpu_sim.py: pure-Python cycle-accurate interactive simulator with raw terminal mode, --trace, --max-cycles flags - extract_netlist.py: Logisim .circ → netlistsvg-compatible JSON (flood-fill nets, Splitter geometry decoding, 11-cell Yosys JSON) - useless_OS_clean.hex: ROM image assembled from useless_OS_clean.asm - README.md: full architecture docs, ISA table, I/O interface, all tool usage, Verilog/Logisim correspondence, expected sim output - .gitignore: exclude Verilog build artifacts and generated netlist - CLAUDE.md: project guidance for Claude Code
cpu_sim.py: exits cleanly when CPU writes out2=0xFF verilog/cpu.v: document out2=0xFF halt in header comment verilog/tb_cpu.v: detect out2=0xFF and call $finish; keyboard sequence updated to "help\nexit\n"; fixed cycle timeout replaced with safety limit verilog/tb_interactive.v: detect out2=0xFF and call $finish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
verilog/cpu.v— cycle-accurate single-cycle RTL: Harvard architecture, 8-bit datapath, 12-bit instructions, 13-instruction ISA, NAND-only ALU,$readmemhROM initverilog/tb_cpu.v— automated testbench: injectshelp\n, captures TTY output, dumps VCD waveform; terminates in 12 000 cyclesverilog/tb_interactive.v— interactive testbench via Icarus$fgetc; stdin → keyboard, stdout → TTY; exit with Ctrl-Dverilog/Makefile—make sim/make isim/make wave/make cleancpu_sim.py— pure-Python cycle-accurate interactive simulator; raw terminal mode, backspace/Ctrl-D handling,--traceand--max-cyclesflagsextract_netlist.py— Logisim.circ→ netlistsvg-compatible JSON; flood-fills 930 wire segments into 149 nets, decodes Splitter pin geometry, emits 11-cell Yosys-style JSONuseless_OS_clean.hex— ROM image assembled fromuseless_OS_clean.asmREADME.md— full architecture docs, ISA table, memory map, I/O interface, tool usage, Verilog/Logisim correspondence table, expected simulation output.gitignore— exclude Verilog build artifacts and generated netlist filesTest plan
cd verilog && make sim— automated testbench prints banner, responds tohelp, terminates cleanly at cycle 12003cd verilog && make isim— interactive shell accepts keyboard input, exit with Ctrl-Dpython3 cpu_sim.py— Python interactive shell, same behaviourpython3 extract_netlist.py --summary— prints net table, writescpu_netlist.json(11 cells, 149 nets)python3 assembler.py useless_OS_clean.asm— all 182 instructions matchuseless_OS.hexexactly