Skip to content

Latest commit

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

LC3 Virtual Machine for mcpp

made-with-cppcreator-justinmeinersadapted-by-rozukkeGitHub license

This is a C++ based virtual machine for the LC3 assembly language, adapted to work with mcpp the Royal Melbourne Institute of Technology (RMIT) to supplement the COSC2084 (Programming Studio 2) course. The original project by Justin Meiners can be found here. Thank you to Michael Dann for the original adaptation and trap implementations.

Additions

This VM supports a few additional TRAPs based on mcpp functionality, including:

  • CHAT to post to Minecraft chat
  • GETP to get player position
  • SETP to set player position
  • GETB to get block type
  • SETB to set block type
  • GETH to get max height at an x,z coordinate As well as:
  • REG to print out registers to console. By default, it will print as unsigned, but the VM supports flags to print as:
    • -d signed
    • -x hexadecimal
    • -b binary

Usage

lc3 [-FLAG] <file.obj> where file.obj is a compiled binary. -FLAG is a single letter flag based on the above Additions section.

Installation

Designed to install on UNIX-based systems. Run make in the root directory and then sudo make install to make the command globally available.

TRAP formats

TRAPmcpp functionDescription
CHATpostToChat(R0)Outputs a null terminating string starting at the address contained in R0 to the Minecraft chat.
GETPgetPlayerPosition() -> R0, R1, R2Gets the position of the player. The x, y and z coordinates are output in registers R0, R1 and R2 respectively.
SETPsetPlayerPosition(R0, R1, R2)This function moves the player to the tile (x, y, z) = (R0, R1, R2).
GETBgetBlock(R0, R1, R2) -> R3This function retrieves the block's ID at tile (x, y, z) = (R0, R1, R2) and returns it to R3.
SETBsetBlock(R0, R1, R2, R3)This function changes the ID of the block at tile (x, y, z) = (R0, R1, R2) to the value stored in R3.
GETHgetHeight(R0, R2) -> R1This function calculates the y-position of the highest non-air block at (x, z) = (R0, R2) and returns the value to R1.
REGNon-mcppDebugging function to print registers to console. See above for alternative print modes.

Examples

Two .asm examples are provided, printing a "Hello World" message in the console and in Minecraft. Run the .obj files to test the code out.

About

LC3 virtual machine written in C++ that implements mcpp related TRAPs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages