An assembler and a virtual machine for the LC-3 (Little Computer 3), an educational 16-bit architecture. The assembler turns LC-3 assembly into machine code, and the VM runs that machine code. They do have some limitations so make sure to go over the READMEs properly before using them :)
- Reads LC-3 assembly and produces an object file (
.obj) that the VM can load. - Handles labels, directives and the standard LC-3 instruction set.
- Emulates the LC-3: 16-bit words, 8 general-purpose registers, a program counter and condition flags.
- Implements the full LC-3 instruction set (except RTI) and the standard trap routines (keyboard and console I/O, halt).
- Trap routines are handled via built in C functions.
For build and usage instructions, look inside the Assembler/ and VM/ folders.
| OS | Fedora Linux 44 (x86_64) |
| Compiler | GCC 16.2.1 (GNU mode) |
| Language standard | C23 |
I have only built and tested this on Linux. Other platforms or older compilers may need changes.
I've also added tests for both the assembler and the VM, in the Tests/ folder. They include some larger programs, such as 2048.
- Write your own Virtual Machine (a reference whenever I got stuck)
- Assembly lecture notes, CS 2461 (the assembler reference)
- LC-3 ISA specification (the VM's instruction set reference)
Tests/2048.asm is an implementation of 2048 for the LC-3 by Ryan Pendleton, taken from rpendleton/lc3-2048 and released under the MIT License. I did not write it; I use it as a large real-world test program for the assembler and VM. The original header, including the author and license notice, is kept at the top of the file. All credit for it goes to the original author.