Skip to content

edjroz/lc3-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LC-3 Virtual Machine

A simple virtual machine that runs LC-3 programs, written in C.

What is LC-3?

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.

Building

gcc -o lc3 main.c -Wall

Usage

./lc3 <image-file> [additional-image-files...]

LC-3 programs are distributed as .obj binary image files. Several are available online:

  • 2048 — the sliding tile game
  • Rogue — a roguelike dungeon crawler

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.

Platform

Unix/macOS only (uses POSIX terminal APIs).

Reference

Based on justinmeiners/lc3-vm and rpendleton/lc3sim-c.

About

a lc3 vm implementation in C for educational purposes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages