Giter VIP home page Giter VIP logo

wolf-asm's Introduction

wolf-asm

Build Status Line Count

The Wolf Assembly Language is a made up assembly language for a non-existent machine. This language was originally invented for an assembly-based puzzle game that I was planning to create. I don't know if I'll get the chance to finish that game anytime soon, so I thought I would release the language and VM early.

This repository contains the assembler (./asm) for the language and a virtual machine (./vm) for interpreting the "machine code" generated by that assembler. The assembler is designed to produce good, helpful error messages, not just quit with some arcane error that you can't decipher. There is still a ways to go before the messages are as good as errors produced by the Rust compiler, but I have done quite a bit of work to setup the code so it should be easy to keep improving the errors as I work on it.

The language is loosely based on x86, ARM, and even MIPS assembly. My goal for the first draft was to make a language that was relatively nice to program in and also easy to implement a VM for. The language documentation is currently in the form of some rough notes that I took while designing it. See that document for a reference of the language syntax and supported instructions.

Example Programs

See tests/run-pass for several example programs written using the language. You can also run programs in tests/ui to see some of the error messages.

Here is a program that outputs hello, world!\n and then quits:

section .code

main:
  push $fp
  mov $fp, $sp

  # Loop through and write each character

  # $8 = the address of the current character
  mov $8, message
  # $9 = the address one past the last character in the string
  load8 $9, length
  add $9, message

loop:
  cmp $8, $9
  jge end

  # Load the current character
  load1 $10, $8
  # Write the current character using memory mapped IO
  store8 0xffff_000c, $10
  # Move to the next character
  add $8, 1

  # Continue the loop
  jmp loop

end:
  pop $fp
  ret

section .static

# Declare a string with the message we want to print
message:
  .bytes 'hello, world!\n'
length:
  .b8 14

Building & Running

Make sure you have Rust installed.

Run the assembler using the command:

cargo run -p wolf-asm -- tests/run-pass/hello.wa

This will generate an executable hello in the current directory. Note: this executable is for the Wolf VM, not for your machine.

Run the generated machine code using the command:

cargo run -p wolf-vm -- hello

Running Tests

To run tests, use the following command:

cargo test --all

This will run the tests for the assembler and for the VM.

To regenerate the test output files, use the command:

TESTASSEMBLER=overwrite TESTVM=overwrite cargo test --all

You can omit either TESTASSEMBLER=overwrite or TESTVM=overwrite depending on whether you intend to overwrite the assembler test output files or the VM test output files.

wolf-asm's People

Contributors

sunjay 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.