MicroZ Lab is an interactive web-based platform for learning assembly programming using the MicroZ instruction set architecture, featuring a comprehensive debugger with line awareness and resizable UI.
- Interactive lessons covering MicroZ assembly fundamentals
- Step-by-step tutorials with code examples
- Progress tracking and completion status
- "Open in Debugger" functionality for hands-on practice
- Full-featured assembly debugger with advanced debugging capabilities
- Monaco editor with MicroZ syntax highlighting and intelligent code completion
- Real-time register and memory visualization with hex/decimal views
- Smart breakpoint system with automatic snapping to executable lines
- Multi-panel interface: Registers, Memory, Watches, Console, Trace, Performance
- Console output for system calls with formatted display
- Watch expressions for registers, memory locations, and labels
- Execution trace with instruction history and program flow analysis
- Performance controls with adjustable speed and batch execution
- Sample programs and comprehensive debugger showcase
- Resizable/dockable layout (right, bottom, fullscreen) with persistent preferences
- Comprehensive error handling with actionable messages and suggestions
- Keyboard shortcuts for efficient debugging workflow
- R0-R15: General purpose registers (16-bit)
- SP: Stack Pointer
- BP: Base Pointer
- IP: Instruction Pointer
- ZF: Zero Flag
- NF: Negative Flag
- CF: Carry Flag
- OF: Overflow Flag
- 64KB address space (TEXT at 0x0000, DATA at 0x8000)
- Little-endian byte order
- Stack grows downward from high addresses
MOV dst, src- Move data between registers or load immediateLOAD Rd, [addr]- Load 16-bit word from memory to registerSTORE [addr], Rs- Store register to memory
ADD Rd, src- Addition with flag updatesSUB Rd, src- Subtraction with flag updatesMUL Rd, src- MultiplicationDIV Rd, src- DivisionINC Rn- Increment registerDEC Rn- Decrement register
AND Rd, src- Bitwise ANDOR Rd, src- Bitwise ORXOR Rd, src- Bitwise XORNOT Rn- Bitwise NOTSHL Rd, count- Shift leftSHR Rd, count- Shift right
CMP Ra, Rb- Compare and set flagsJMP label- Unconditional jumpJE label- Jump if equal (Z flag set)JNE label- Jump if not equal (alias for JNZ)JNZ label- Jump if not zeroJG/JGE/JL/JLE label- Signed comparisonsCALL label- Function callRET- Return from function
PUSH Rn- Push register to stackPOP Rn- Pop from stack to register
NOP- No operationHLT- Stop execution (alias: HALT)SYS #n- System call (alias: SYSCALL)SYS #1- Print integer in R0SYS #2- Print string at address in R0SYS #3- Exit with code in R0
- Immediate:
#123,#0x7B,#0b1010,#'A'- Constants - Register:
R0-R15,SP,BP- Register contents - Direct:
[1000],[label]- Memory at address - Indirect:
[R0]- Memory at address in register - Indexed:
[R0+4],[label+offset]- Base + offset
- Decimal:
123 - Hexadecimal:
0x7B,0X7b - Binary:
0b1111011,0B1111011 - Character:
'A'(ASCII value 65)
- Load a Program: Use the Monaco editor to write assembly code or load an example
- Set Breakpoints: Click the gutter margin or press F9 on any line
- Start Debugging: Click Run or press Ctrl+Enter to begin execution
- Step Through Code: Use F10 (step over) or F11 (step into) for line-by-line execution
Add expressions to monitor values during execution:
- Registers:
R0,R15,SP,BP,IP - Memory:
[1000],[0x8000],[label_name] - Indirect:
[R0],[SP+4],[label+offset]
The debugger supports MicroZ system calls for I/O:
SYS #1 ; Print integer in R0
SYS #2 ; Print string at address in R0
SYS #3 ; Exit with code in R0- TEXT Section: 0x0000-0x7FFF (code and instructions)
.TEXT
main:
MOV R0, #42
MOV R1, R0
ADD R1, #10
MOV R0, R1
SYS #1
MOV R0, #0
SYS #3
HLT Debugging Steps:
- Set breakpoint on
MOV R0, #42 - Add watches for
R1andR0 - Run program - execution stops at breakpoint
- Step through each instruction with F10/F11
- Observe register changes in real-time
- Check console output for system call results
Common Issues:
- Breakpoint not hit: Ensure line contains executable instruction
- Invalid memory access: Check address bounds (0x0000-0xFFFF)
- Undefined label: Verify label is declared and spelled correctly
- Stack overflow: Monitor SP register, ensure balanced PUSH/POP
Error Messages: The debugger provides detailed error information with:
- Line and column numbers
- Specific error descriptions
- Suggestions for common mistakes
- Syntax highlighting for problematic code
Watch Expression Examples:
R0- Register R0 value[1000]- Memory at address 1000[msg_hello]- Memory at label address[R0]- Memory at address in R0[SP+4]- Memory at SP + 4 offset
System Call Reference:
SYS #1- Print integer in R0 to consoleSYS #2- Print null-terminated string at address in R0SYS #3- Exit program with code in R0
Try the Showcase:
Load examples/debugger-showcase.asm for a comprehensive demonstration of all debugger features including breakpoints, stepping, watches, memory inspection, and system calls.
- Node.js 18+
- npm or yarn
npm install
npm run devThe MicroZ debugger can be used independently of the learning platform:
# Run standalone debugger
npm run dev:debugger
# Test debugger functionality
npm run test:debugger
# Run smoke tests
npm run smoke:debuggerimport { DebuggerStandalone } from '@microz/debugger';
<DebuggerStandalone
initialFile="examples/hello.asm"
theme="system"
readonly={false}
initialBreakpoints={[{ path: 'main.asm', line: 5 }]}
/>Props:
| Prop | Type | Default | Description |
|---|---|---|---|
initialFile |
string |
- | Load example file on mount |
readonly |
boolean |
false |
Disable code editing |
theme |
'light'|'dark'|'system' |
'dark' |
Editor theme |
initialBreakpoints |
Array<{path:string; line:number}> |
[] |
Set breakpoints on load |
Core Debugging:
- Smart Breakpoints: Click gutter or F9 to toggle, automatic snapping to executable lines
- Step Execution: F10 (step over), F11 (step into), Shift+F11 (step out)
- Run Control: Run until breakpoint/halt, pause execution, reset CPU state
- Line Awareness: Visual feedback when breakpoints snap to nearest executable line
Multi-Panel Interface:
- Registers Panel: R0-R15 general purpose, SP/BP/IP special registers, CPU flags (ZF/NF/CF/OF)
- Memory Viewer: Hex/decimal display, navigate to addresses, inspect data section
- Watch Expressions: Monitor registers (
R0), memory ([1000]), labels ([msg_hello]) - Console Output: System call results, string/integer prints, program messages
- Trace Panel: Execution history, instruction sequence, program flow analysis
- Performance Controls: Adjustable speed, batch execution, execution statistics
Advanced Features:
- Resizable Layout: Dock right (40%), bottom (30%), or fullscreen with persistent preferences
- Keyboard Shortcuts: F9 (breakpoint), F10 (step over), F11 (step into), Ctrl+B (focus registers), Ctrl+Enter (run)
- Error Recovery: Robust error boundaries with copy stack and reset functionality
- Source Mapping: Accurate line mapping between editor and runtime with position utilities
- Instruction Aliases: HALT→HLT, JNE→JNZ, SYSCALL→SYS with case-insensitive parsing
- Comprehensive ISA: 16 registers (R0-R15), multiple addressing modes, full directive support
- Actionable Errors: Line/column precision with suggestions for typos and common mistakes
- Memory Layout: Separate TEXT (0x0000) and DATA (0x8000) sections with configurable bases
Example Programs:
examples/hello.asm- Basic program structure and system callsexamples/controlflow.asm- Loops, conditionals, and jumpsexamples/directives.asm- Data section and assembler directivesexamples/debugger-showcase.asm- Comprehensive feature demonstration
# Run all tests
npm test
# Test debugger functionality
npm run test:debugger
# Test example programs
npm run test:showcase
# Run smoke tests
npm run smoke:debuggernpm run build- React 18 - UI framework
- TypeScript - Type safety
- Vite - Build tool and dev server
- Tailwind CSS - Styling
- Monaco Editor - Code editor
- Web Workers - Off-main-thread execution
- Monaco editor lazy-loaded
- Code execution in Web Workers
- Component code-splitting
- Efficient memory visualization
- Debounced localStorage saves
- Keyboard shortcuts (F9, F10, F11, Ctrl+Enter)
- High contrast mode support
- Screen reader friendly
- Large touch targets for mobile
- Responsive design
- Touch-friendly controls
- Collapsible panels
- Optimized for small screens
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
- Complete Web Worker implementation
- Advanced debugging features
- More interactive lessons
- Challenge system with grading
- Export/import programs
- Collaborative features
- Performance profiling tools