HSE Student project for an LC-3 (Little Computer 3) Virtual Machine implementation in C++.
This project implements a functional LC-3 virtual machine that can load and execute LC-3 assembly programs (.obj
files). It includes a CPU, memory, and support for various LC-3 instructions and trap routines for basic I/O.
- Instruction Set: Implements the standard LC-3 opcodes:
ADD
,AND
,NOT
BR
(Branch)JMP
(Jump),RET
(Return from Subroutine viaJMP R7
)JSR
,JSRR
(Jump to Subroutine)LD
,LDI
,LDR
(Load)ST
,STI
,STR
(Store)LEA
(Load Effective Address)RTI
(Return from Interrupt - placeholder, not fully implemented)RES
(Reserved - placeholder)
- Trap Routines: Supports common TRAP routines:
TRAP_GETC
: Get character from keyboard (not echoed).TRAP_OUT
: Output a character to the console.TRAP_PUTS
: Output a null-terminated string.TRAP_IN
: Get character from keyboard (echoed) with prompt.TRAP_PUTSP
: Output a null-terminated string of packed characters.TRAP_HALT
: Halt the program.
- Memory-mapped I/O: Keyboard Status Register (
KBSR
) and Keyboard Data Register (KBDR
) are implemented. - Unit Tests: Includes a suite of unit tests using Google Test to verify instruction behavior.
- Documentation: Source code documentation can be generated using Doxygen.
- CI/CD: Basic GitHub Actions workflow for building and testing on push/pull request.
To build and run this project, you will need:
g++
(with C++14 support or newer)make
- Google Test (
libgtest-dev
on Debian/Ubuntu systems) doxygen
(optional, for generating documentation)
The project can be built using either CMake or Make. Choose your preferred method below.
-
Create a build directory and navigate to it:
mkdir build cd build
-
Generate build files:
cmake ..
-
Build the project:
cmake --build .
This will create the following executables in the
build
directory:lc3vm
: The main VM executabletest_runner
: The test executable
-
Run tests (optional):
./test_runner
-
Generate documentation (optional):
cmake --build . --target docs
-
Navigate to the
lc3vm
directory:cd lc3vm
-
Build the VM:
make
This will create the executable
build/lc3vm
inside thelc3vm
directory. -
Build the tests: The test executable
build/test_runner
(insidelc3vm
) is also built by the defaultmake
target or specifically withmake test_runner
. -
Clean build files:
make clean
To run an LC-3 object file:
./lc3vm/build/lc3vm path/to/your_program.obj [path/to/another_program.obj ...]
The LC-3 VM can also disassemble .obj
files, showing you the LC-3 assembly instructions corresponding to the machine code in the file. This is useful for inspecting programs or debugging.
How to use:
To disassemble one or more object files, use the -d
or --disassemble
flag followed by the path(s) to your .obj
file(s):
./lc3vm/build/lc3vm -d path/to/your_program.obj
Or for multiple files:
./lc3vm/build/lc3vm --disassemble program1.obj program2.obj
To compile and run the unit tests (from within the lc3vm
directory):
make test
.
├── .github/ # GitHub Actions workflows
├── docs/ # Generated Doxygen documentation (after 'make docs')
├── lc3vm/ # Main directory for the VM
│ ├── Doxyfile # Doxygen configuration file
│ ├── Makefile # Makefile for building the VM and tests
│ ├── build/ # Build output directory (executables, object files)
│ ├── include/ # Header files for the LC-3 VM
│ ├── src/ # Source files for the LC-3 VM
│ └── tests/ # Unit test source files (using Google Test)
├── README.md # This file
└── LICENSE # Project License