A virtual machine implementation of the LC-3 (Little Computer 3) architecture in C.
The LC-3 is a 16-bit educational computer architecture used in introductory computer science courses. This VM can run LC-3 machine code programs, including games like 2048 and Rogue.
- Complete implementation of all 15 LC-3 opcodes
- Memory-mapped I/O (keyboard and display)
- Trap routines (GETC, OUT, PUTS, IN, PUTSP, HALT)
- Terminal raw mode for real-time keyboard input
gcc -o lc3 main.c./lc3 <program.obj>Example:
./lc3 2048.obj- 16-bit address space (65,536 memory locations)
- 8 general-purpose registers (R0-R7)
- Program Counter (PC) and Condition Register (COND)
- Condition flags: Negative, Zero, Positive
| Opcode | Name | Description |
|---|---|---|
| 0000 | BR | Conditional branch |
| 0001 | ADD | Add |
| 0010 | LD | Load |
| 0011 | ST | Store |
| 0100 | JSR | Jump to subroutine |
| 0101 | AND | Bitwise AND |
| 0110 | LDR | Load register |
| 0111 | STR | Store register |
| 1000 | RTI | Return from interrupt |
| 1001 | NOT | Bitwise NOT |
| 1010 | LDI | Load indirect |
| 1011 | STI | Store indirect |
| 1100 | JMP | Jump |
| 1101 | RES | Reserved |
| 1110 | LEA | Load effective address |
| 1111 | TRAP | System call |
2048.obj- The 2048 sliding tile game (included)