A C++ implementation of the LC-3 (Little Computer 3) virtual machine.
This project simulates the LC-3 CPU, memory, instruction execution cycle, and terminal I/O behavior needed to run LC-3 object programs such as 2048.
- 16-bit LC-3 architecture simulation
- 65,536 memory locations
- Full fetch-decode-execute loop
- Implemented core instruction groups:
- Arithmetic/logic:
ADD,AND,NOT - Data movement:
LD,ST,LDR,STR,LDI,STI,LEA - Control flow:
BR,JMP,JSR/JSRR - System calls:
TRAProutines (GETC,OUT,PUTS,IN,PUTSP,HALT)
- Arithmetic/logic:
- Memory-mapped keyboard registers (
KBSR,KBDR) - LC-3 object image loading with endianness conversion
- Terminal raw-mode input handling for interactive programs
lc3.hpp- VM declarations, enums, and class interfacelc3.cpp- VM implementation (instructions, memory, traps, runtime loop)main.cpp- CLI entry point and image loadingMakefile- build rules (all,clean,fclean,re,run)programs/- sample LC-3 object programs
makeRun with one LC-3 object file:
./lc3-vm programs/2048.objmake/make all- build executablemake clean- remove object filesmake fclean- remove object files and executablemake re- full rebuild (fcleanthenall)make run- run executable
- On launch of some programs (like 2048), you may be prompted with terminal capability questions.
- Controls for 2048 are typically
W,A,S,D.
This implementation is based on and inspired by the LC-3 VM article: