Skip to content

noahbean33/virtual_machine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lc3-vm

A complete LC-3 virtual machine implementation in Rust.

Features

  • Full implementation of all 15 LC-3 opcodes
  • Dual-mode trap handling (native Rust fallback + OS vector dispatch)
  • Memory-mapped I/O: KBSR, KBDR, DSR, DDR, MCR
  • Cross-platform terminal support (Unix + Windows)
  • Bundled LC-3 OS image for full hardware fidelity
  • MCR-based halt mechanism (matches real hardware)
  • PSR (Processor Status Register) with NZP condition codes
  • Feature-gated instruction tracing for debugging
  • Typed instruction decoding with unit tests
  • Result-based error handling (no panics in core logic)

Usage

# Run a program with OS support (default)
cargo run -- program.obj

# Run without OS (traps handled natively)
cargo run -- --no-os program.obj

# Run with instruction tracing (requires --features trace)
cargo run --features trace -- --trace program.obj

# Load multiple images
cargo run -- os_extensions.obj program.obj

Architecture

src/
├── main.rs          # CLI, signals, terminal lifecycle
├── vm.rs            # VM struct, fetch-decode-execute loop
├── memory.rs        # 64K memory + MMIO registers
├── cpu.rs           # Opcode execution handlers
├── instructions.rs  # Typed instruction decoding structs
├── trap.rs          # Trap dispatch (native + OS vector)
├── terminal.rs      # Platform-abstracted terminal I/O
└── error.rs         # Error types

Building

cargo build --release

Testing

cargo test

References

Status

In development — see PLAN.md for implementation roadmap.

About

Implementation of the LC-3 virtual machine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors