|
LC3 VM 1.0
A simple LC-3 Virtual Machine
|
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.
ADD, AND, NOTBR (Branch)JMP (Jump), RET (Return from Subroutine via JMP 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_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.KBSR) and Keyboard Data Register (KBDR) are implemented.To build and run this project, you will need:
g++ (with C++14 support or newer)makelibgtest-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:
Generate build files:
Build the project:
This will create the following executables in the build directory:
lc3vm: The main VM executabletest_runner: The test executableRun tests (optional):
Generate documentation (optional):
Navigate to the lc3vm directory:
Build the VM:
This will create the executable build/lc3vm inside the lc3vm directory.
build/test_runner (inside lc3vm) is also built by the default make target or specifically with make test_runner.Clean build files:
To run an LC-3 object file:
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):
Or for multiple files:
To compile and run the unit tests (from within the lc3vm directory):