#assembly #hack #machine

bin+lib rhasm

A Rust implementation of the hasm assembler

4 releases

0.2.0 Sep 27, 2024
0.1.2 Sep 6, 2024
0.1.1 Sep 3, 2024
0.1.0 Sep 3, 2024

#3 in #hack

Download history 328/week @ 2024-08-31 54/week @ 2024-09-07 60/week @ 2024-09-14 53/week @ 2024-09-21 65/week @ 2024-09-28 7/week @ 2024-10-05 2/week @ 2024-10-12

133 downloads per month

MIT/Apache

215KB
29K SLoC

Assembly 28K SLoC Rust 617 SLoC // 0.0% comments

RHASM (Rust Hack Assembler)

This is a simple assembler for the Hack assembly language, written in Rust. The assembler can be used as a cli tool or as a library in your Rust project. Rhasm requires the input file to be a valid Hack assembly file, and it will output a Hack machine code file. The assembler supports all Hack assembly instructions, including A-instructions, C-instructions, and L-instructions. An example of a valid Hack assembly file is included as sample.asm.

Installation

As a CLI tool

To install the cli tool make sure cargo is installed (you can install cargo from here), then run the following command:

cargo install rhasm

As a library

To use the library in your project, add the following to your Cargo.toml:

[dependencies]
rhasm = "0.1.0"

Or you can use cargo to add the dependency:

cargo add rhasm

Then import the library in your project:

use rhasm;

let asm = rhasm::Assembler::build(&in_file, &out_file);
// Then you can use the asm object to assemble the file

Usage

Rhasm exposes two ways to assemble Hack assembly code, the first is through a binary cli tool and the second is through a library.

CLI Example

To use rhasm as a cli tool, you can run the following command:

rhasm <input_file> [-o | --output <output_file>] [-d | --disassemble [--with_symbols <symbol_file>]]

Library Examples

Code examples can be found in the crate's documentation

Dependencies

~3.5–5MB
~87K SLoC