Giter Site home page Giter Site logo

lc3-vm-c's Introduction

My LC-3 VM implementation in C, following jmeiners' LC-3 VM tutorial.

See also lc3-vm-tutorial-c for just the tutorial scaffolding with the opcodes left as an exercise for the reader.

LC-3 is an educational 16-bit computer architecture with 16 opcodes and 8 general-purpose registers. However, R7 is usually reserved for return addresses. Data is stored in two's complement representation. Some I/O operations are provided through TRAP instructions.

How to

Setup

Install gcc. You will use gcc to compile your C file into an executable.

  • MacOS: brew install gcc
  • Unix: sudo apt-get install gcc

Optional setup: assembler

If you want to be able to write any of your own intermediate test cases in Assembly, set up the LC-3 tools.

Follow their setup instructions. You should then be able to run the assembler on an assembly file, like so:

lc3as roms/hello.asm

Emulate a rom

Assembly files and assembled roms live in roms/.

To run a rom on the VM, pass the .obj file path to the VM executable.

./lc3-vm roms/hello.obj

If you have not implemented anything yet, you should see an error message about an op not being implemented.

If you installed the LC-3 tools, you can use my Make targets as shorthand to assemble new roms. For example, to reassemble and run roms/hello.asm, do make run rom=roms/hello.

Compile the VM

When you make changes to the LC-3 implementation, you'll want to recompile the C code to an executable.

You can use make compile as shorthand. To see what it does, read Makefile.

Assembly instruction quickref (incomplete)

Instruction Outcome
ADD R0 R1 R2 R0 = R1 + R2
ADD R0 R1 # R0 = R1 + #, where # < 2^5
AND R0 R1 R2 R0 = R1 & R2
AND R0 R1 # R0 = R1 & #, where # < 2^5
NOT R0 R1 R0 = ^R1
BRn LABEL Jump if result is -
BRz LABEL Jump if result == 0
BRp LABEL Jump if result is +
BRzp LABEL Jump if result is 0 OR +
BRnp LABEL Jump if result is - OR +
BRnz LABEL Jump if result is - OR 0
BRnzp LABEL Jump if result is -
JMP R0 Jump to addr in reg (may use R0-R6)
JSR LABEL Jump to label
JSRR R0 Jump to addr in R0
RET Return to addr in R7

Misc utils

decimal -> binary

Smol python3 script to check what a decimal integer looks like in binary.

Usage: ./binary.py <number>

truth table checker

Double check the outputs for the boolean functions in truth_tables.c.

Usage: make truth

lc3-vm-c's People

Contributors

rfong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.