A simple virtual machine that runs LC-3 programs, written in C.
The LC-3 (Little Computer 3) is a simplified computer architecture used to teach the fundamentals of computing. It features:
- 16-bit address space (65,536 memory locations)
- 8 general-purpose registers (R0–R7) plus a program counter and condition flags register
- 15 opcodes — arithmetic (ADD, AND, NOT), memory access (LD, LDI, LDR, ST, STI, STR, LEA), control flow (BR, JMP, JSR), and system calls (TRAP)
- 3 condition flags — negative, zero, positive (set after every register write)
- 6 trap routines — basic I/O (GETC, OUT, PUTS, IN, PUTSP) and HALT
Despite its simplicity, the LC-3 is expressive enough to run non-trivial programs like games and text adventures.
gcc -o lc3 main.c -Wall
./lc3 <image-file> [additional-image-files...]
LC-3 programs are distributed as .obj binary image files. Several are available online:
Download an .obj file and run it:
./lc3 2048.obj
Press Ctrl+C to quit. The terminal will be restored to its normal state automatically.
Unix/macOS only (uses POSIX terminal APIs).
Based on justinmeiners/lc3-vm and rpendleton/lc3sim-c.