A son of MARS (but in a different language). A modern, interactive web-based port of the classic MARS MIPS simulator, built with React, Monaco Editor, and a complete MIPS execution engine implemented in TypeScript.
- β Complete MIPS Assembler: Lexer β Parser β Machine Code Generator
- β Full MIPS Simulator: Execute MIPS instructions with accurate register/memory state
- β Monaco Editor: Professional syntax highlighting and code editing
- β Real-time Execution: Assemble and run MIPS programs instantly
- β Register Viewer: Monitor all 32 MIPS registers in real-time, with Coproc 1 and Coproc 0 tabs
- β Memory Inspector: View memory contents during execution
- β Console I/O: Output plus in-console input for supported syscalls
- β
Data Segments: Initialize memory with
.data, labels, strings, and numeric values - β Interactive Debugging: Assemble, toggle source breakpoints, step, continue, and step back
- β
Call Stack View: Inspect active
jal/jalrcalls while stepping - β Source Workspace: Multiple source tabs and find/replace
- β Portable Export: Download assembled text in THRAX HexText format
- β Bitmap Display: Render word-addressed 24-bit RGB framebuffer memory
- β Keyboard/Display MMIO: Queue keyboard input and inspect transmitter output at the standard THRAX device addresses
- β Example Programs: 8 ready-to-run MIPS programs
- β Dark Theme UI: VS Code-inspired interface
Arithmetic: ADD, ADDI, ADDU, ADDIU, SUB, SUBU, MUL, MULT, MULTU, DIV, DIVU
Logical: AND, ANDI, OR, ORI, XOR, XORI, NOR
Shifts: SLL, SRL, SRA, SLLV, SRLV, SRAV
Comparison: SLT, SLTI, SLTU, SLTIU
Load/Store: LW, LH, LHU, LB, LBU, SW, SH, SB, LUI, LA
Jump & Branch: BEQ, BNE, BGEZ, BGTZ, BLEZ, BLTZ, BLT, BLE, BGT, BGE, J, JAL, JR, JALR
Special: MFHI, MFLO, MTHI, MTLO, NOP, MOVE, LI, SYSCALL
Coprocessor 1 (floating point): LWC1, SWC1, LDC1, SDC1, MFC1, MTC1, ADD/SUB/MUL/DIV/ABS/NEG/SQRT/MOV (.s and .d), CVT.S.W, CVT.S.D, CVT.D.W, CVT.D.S, CVT.W.S, CVT.W.D, ROUND/TRUNC/CEIL/FLOOR.W (.s and .d), C.EQ/C.LT/C.LE (.s and .d), BC1T, BC1F, MOVT, MOVF. Comparisons and branches use condition flag 0; double-precision operands take the even register of an even/odd pair.
Coprocessor 0 (system control): MFC0, MTC0, ERET. The register file exposes $8 (vaddr), $12 (status), $13 (cause), and $14 (epc), reachable by number or by the $status-style aliases.
Assembler pseudos: LA, B, BAL, BEQZ, BNEZ, BLT/BLE/BGT/BGE (and unsigned variants), NOT, NEG, NEGU, ABS, SEQ/SNE/SGT/SGE/SLE (and unsigned variants), REM, REMU, L.S, L.D, S.S, S.D, LI.S, LI.D. These are expanded to base MIPS instructions before addresses and branch offsets are assigned, so they work in debugging and HexText exports.
1: Print integer4: Print string (null-terminated)5: Read integer8: Read string9: Allocate heap memory (sbrk)10: Exit program11: Print character12: Read character17: Exit with code2,3: Print float from$f12or double from$f12/$f136,7: Read float or double into$f034,35,36: Print integer as hexadecimal, binary, or unsigned decimal
The Keyboard and Display Simulator uses the original THRAX MMIO addresses:
0xffff0000 receiver control, 0xffff0004 receiver data, 0xffff0008
transmitter control, and 0xffff000c transmitter data. Receiver and
transmitter readiness use bit 0. Reading receiver data consumes one queued
character; writing transmitter data appends its low byte to the tool display.
- Segments:
.data,.text,.kdata,.ktext, each accepting an optional base address such as.ktext 0x80000180 - Storage:
.word,.half,.byte,.float,.double,.ascii,.asciiz,.space,.align - Symbols:
.globl,.global,.extern name, size(which reservessizezeroed bytes in the data segment),.eqv - Program structure:
.macro/.end_macro,.include "file.asm", and.set, which is accepted and ignored
- Registers by name or number:
$t0and$8are the same register, as are$raand$31 - Character literals are integers:
li $t0, 'a',.byte 'a', ' ' - Label expressions add a constant to a label:
la $t0, arr+4,lw $t1, arr+4($s0),.word arr+8
Each editor tab is a file, and double-clicking a tab renames it. .include "lib.asm"
pulls in another open tab by name, and the toolbar's All files switch assembles
every open tab into one program instead of only the active one. Files share one
symbol table, so labels resolve across them; the active tab supplies the entry point,
which is the main label when the program defines one.
- Frontend: React 18 + TypeScript + Vite
- Code Editor: Monaco Editor
- State Management: Zustand
- Styling: CSS3
- Build Tool: Vite
- Node.js 16+
- npm or yarn
# Clone the repository
git clone https://github.com/Spongman/THRAX.git
cd THRAX
# Install dependencies
npm install
# Start development server
npm run dev
# Open browser to http://localhost:3000# Build for production
npm run build
# Preview production build
npm run preview# Compute 5 + 3
addi $t0, $zero, 5
addi $t1, $zero, 3
add $t2, $t0, $t1
move $a0, $t2
addi $v0, $zero, 1
syscall
addi $v0, $zero, 10
syscall
# Print 1 through 5
addi $t0, $zero, 1
loop:
addi $t1, $zero, 6
beq $t0, $t1, done
move $a0, $t0
addi $v0, $zero, 1
syscall
addi $t0, $t0, 1
j loop
done:
addi $v0, $zero, 10
syscall
src/
βββ core/
β βββ lexer.ts # Tokenization
β βββ parser.ts # AST generation
β βββ assembler.ts # Machine code generation
β βββ simulator.ts # Execution engine
β βββ mipsLanguage.ts # Monaco syntax support
β βββ index.ts # Exports
βββ components/
β βββ Toolbar.tsx # Run/Reset/Examples
β βββ RegisterView.tsx # Register display
β βββ MemoryView.tsx # Memory inspector
β βββ BitmapDisplay.tsx # Memory-mapped RGB framebuffer tool
β βββ KeyboardDisplayTool.tsx # THRAX keyboard/display MMIO tool
β βββ ConsoleOutput.tsx # Program output
βββ store/
β βββ thraxStore.ts # Zustand state management
βββ hooks/
β βββ useExamples.ts # Example loader hook
βββ App.tsx # Main application
βββ examples.ts # Example programs
-
Lexical Analysis (
Lexer)- Tokenizes assembly source code
- Recognizes instructions, registers, labels, immediates
-
Parsing (
Parser)- Builds AST from tokens
- Resolves labels and addresses
- Validates syntax
-
Assembly (
Assembler)- Encodes instructions to machine code
- Handles R-type, I-type, J-type formats
- Calculates branch offsets
-
Simulation (
MipsSimulator)- Executes machine code instruction-by-instruction
- Manages 32 registers + special registers (HI, LO, PC) and the CP0/CP1 register files
- Simulates memory (4MB)
- Handles syscalls
- Core MIPS assembler and simulator
- All basic instruction types (R, I, J)
- Arithmetic operations
- Logical operations
- Load/store operations
- Branch and jump instructions
- Multiply/divide with HI/LO registers
- Syscall handling (print int, char, exit)
- Monaco Editor integration
- Register and memory viewers
- Example programs
- Error reporting
- MIPS syntax highlighting
- Step-through debugging and backstepping
- Breakpoint support
- Call stack viewer
- Bitmap display tool (24-bit RGB words, configurable base address)
- Keyboard/display MMIO tool (receiver/transmitter data registers)
- Interactive input (syscalls 5, 8, 12)
- Assembly directives and initialized data segments
- Floating-point instructions (coprocessor 1) and coprocessor 0 registers
- Cache simulation (configurable blocks, associativity, and replacement)
- Pipeline visualization (five-stage timeline with per-cycle stages)
- Data hazard detection (RAW, with and without forwarding)
- Control hazard visualization (branch and jump resolved in ID, EX, or MEM)
- Branch prediction in the pipeline (static, 1-bit, and 2-bit)
- Instruction statistics and branch prediction (BHT) tools
- MIPS X-Ray: the animated datapath, control unit, ALU control, and register bank, drawn as themed SVG
- Delayed branching, as THRAX's setting of the same name
- Assembly program templates
- Save/load programs to browser storage
- Export machine code to HexText
- Dark/light theme toggle
- Keyboard shortcuts
- Mobile responsive design
- Multiple source tabs (each tab assembles independently)
- Collaborative editing
- GPU accelerated simulation
- VR visualization mode
- AI-powered assembly generation
- Formal verification of programs
The staged architecture for bringing the original THRAX capability set to the web port is documented in docs/FEATURE_ARCHITECTURE.md.
- Coprocessor 1 covers single and double precision arithmetic, conversion, comparison, and moves; the FCSR is modelled as the eight condition flags only, so rounding mode selection and exception enables are not configurable
- Coprocessor 0 provides the vaddr/status/cause/epc registers,
mfc0,mtc0, anderet. A.ktexthandler at0x80000180receives traps; without one, a trap records its cause and EPC and stops execution - A label expression takes one label plus a constant (
arr+4); differences of two labels are rejected - A text segment can be based only before it emits instructions, since pseudo-instructions expand after parsing
- Syscall support is intentionally partial; unsupported syscall numbers stop safely with an error
- Maximum 100,000 instruction execution limit (safety); execution yields between batches so runaway code does not block the page
- Sparse virtual memory supports standard THRAX data and stack addresses; the inspector shows the first 100 initialized words
For detailed MIPS instruction set reference, see the original THRAX documentation:
Contributions are welcome! Please feel free to:
- Report bugs
- Suggest features
- Submit pull requests
- Improve documentation
MIT License - Same as the original THRAX simulator
Original THRAX developed by Pete Sanderson and Ken Vollmar. Web port developed by Spongman.
The X-Ray wire graph in src/tools/xray/datapaths.ts is generated from THRAX
4.5's datapath XML by scripts/generate-xray-datapaths.py. The drawings
themselves are redrawn as themed SVG rather than copied.
- Original THRAX: Pete Sanderson and Ken Vollmar
- Monaco Editor: Microsoft
- React: Meta
- Zustand: Poimandres
For issues, questions, or suggestions:
- Check existing GitHub Issues
- Create a new issue with detailed description
- Include example code if reporting a bug
This simulator is designed for educational purposes. It's perfect for:
- Learning MIPS assembly language
- Understanding computer architecture
- Studying processor execution models
- Debugging assembly programs
- Teaching low-level programming concepts
Try it now: THRAX