Crate mlem_asm [] [src]

mlem-asm is an assembler library for MLeM, the Machine Learning Machine. This is a Harvard architecture machine with immutable programs, 8 general purpouse registers, and a hardware-supported stack with stack and base pointers.

Assembly Language

mlem-asm assembles the mlasm language into CBOR-encoded data that can be read and executed by MLeM. The mlasm language looks like so:

; Anything following a semicolon is a comment.
; Lines can be terminated with a semicolon, or not. The following two lines are equivalent:
noop
noop;
; Instructions that require arguments look like so:
move R:R0 R:R1 ; Set R1 equal to R0

Examples

Here is an example of parsing a program and converting it into CBOR.

use mlem_asm::*;
use std::io::Cursor;
let valid_program = "
   noop
   move R:R0 R:SP;
   input R:R0;
   ; comment only

   ";

   let mut buffer = Cursor::new(Vec::<u8>::new());

   let program = parse_program(valid_program).unwrap();
   program_to_writer(&program, &mut buffer).unwrap();
   assert_eq!(buffer.get_ref(), 
              &[217, 217, 247, 131, 0, 131, 2, 130, 
                0, 0, 130, 0, 8, 130, 4, 130, 0, 0])
   

Reexports

pub use parse::parse_program;

Modules

lex
parse

Enums

Address

Represents a place a value can come from: a register, a memory address, a pointer to memory stored in a register, or a literal value.

Instruction

Possible instructions for the machine to execute. For each instruction, the first operand is a, second is b, et cetera

Register

Specifies a register in the machine.

Functions

program_to_writer

Writes an assembled program to a writer in packed, self-describing CBOR (a format MLeM can natively consume.)

Type Definitions

Program

Represents a program; a list of instructions, to be executed in order.