Code Monkey home page Code Monkey logo

lc3-vm-tutorial-c's Introduction

This is example C scaffolding and toolchain setup guidance for following jmeiners' LC-3 VM tutorial, set up in a way that I think is easier to follow. The original tutorial puts a lot of setup code near the end, so it can be hard to check your progress partway through.

The tutorial's enums, setup code, and memory management are provided so you don't have to copypasta everything in from the tutorial. Just instruction set implementations are left as an exercise for the reader. However, I still recommend going through all the scaffolding code line by line to get the educational benefits.

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.

lc3-vm-tutorial-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.