rvmasm

Crates.iorvmasm
lib.rsrvmasm
version1.7.1
created_at2025-07-29 19:02:36.028449+00
updated_at2025-08-23 19:01:01.693437+00
descriptionAssembler for RvmASM
homepage
repository
max_upload_size
id1772697
size57,752
LordAfterEight (LordAfterEight)

documentation

README

RvmASM Assembler

This is the assembler for .rvmasm files. It will parse any file of that type and convert it into binary file for Rusty-VM to read. to use it, first run the following command:

cargo install rvmasm

Now you can use the rvmasm command to build a binary from any .rvmasm input file:

rvmasm code.rvmasm output

Documentation

RvmASM is an Assembly-ish language for my 16-bit virtual machine Rusty-VM. I made this assembly language and its parser to allow me and maybe even others to easily create programs for the virtual machine without needing to write raw binary values into a file. It is currently under development, just like the virtual machine itself, so both are far from being finished. Under this paragraph you will find a documentation of the entire language. This documentation will constantly change as more features and content are added to the language.

Table of Contents

1. Keywords

Types 2. Routines Other
lit routine: var
hex end col
num reg
str

3. Instructions

Jump Register Arithmetics Miscellaneous
jump load comp noop
juie stor radd setv
juin rsub draw
bran rmul ctrl
brie rdiv
brin
rtor

Keywords

These are mostly used to determine how the following value will be interpreted. There are seven keywords: routine:, end, lit, hex, num, str and col.

All number types can have a value from 0 to 61439 (0xEFFF) but must not be bigger. lit, hex and num are always interchangeable as they're just different representations of the same value.

routine:

Explanation

routine: starts the definition of a routine. Example:

routine: routine1       # Creates a routine with the name routine1
...

end

Explanation

end is used to mark the end of the routine. Example:

...
end      # All that's needed to end the routine definition

var

Explanation

var is used to create variables. Currently a variable can only hold a single value (i.e. not a str) from 0x0 to 0xEFFF. Variables can be loaded into registers, be stored to from registers or be printed to the screen using draw var <variable>. Examples:

var age = num 34
var addr = lit 0xBEEF

lit

Explanation

lit will use the given value as is (thus "lit" for "literal") without any conversion, which is why the value must not be longer than four characters (without the prefix) and it must not contain any special symbols; only 0-9and A-F are allowed. Especially useful when you need to specify addresses. Examples:

lit 0x0FA3
lit 0FA3
lit FA3
# These are all the same

hex

Explanation

hex Interprets the following value as character, converting it to its numerical ASCII representation. A hex must only be a single character. Examples:

load A hex U        # "U" will be converted to 0x0055 and loaded into Register A
load A lit 0x0055   # Same value

num

Explanation

num enables you to use any decimal number from 0 to 61439. Examples:

load A num 7        # Number 7 will be loaded into the A register. Would be the same as "lit 0x0007"
load B num 61439    # Number 61439 will be loaded into the B register. Would be the same as "lit 0xEFFF"

str

Explanation

str is currently only used for drawing and will simply convert each character into a u16 that will be stored into the GPU buffer without interruption. The assembler will automatically add an escape character ("`") to the end of the string so the GPU knows when to exit drawing mode. Whitespace is not allowed inside a str, use the character ^ instead. Example:

draw str Hello^World!  # Will print "Hello World!" to the screen

col

Explanation

col is currently only used for drawing. It is placed behind a str to color it. You can also just not use it, then the assembler will default to making the str white. Example:

draw str Hello^World! col red  # Will print a red "Hello World!" to the screen

reg

Explanation

reg is used to tell some instructions to get the value from the specififed register. It is needed for instructions that aren't directly linked to the registers, e.g. the comp instruction. There are four available registers: A, B, C and D. Example:

comp reg A num 8   # Compares the register A to the number 8, setting the eq_flag accordingly

Routines

routine: <RoutineName> is used to create a routine. Every line below a routine: <RoutineName> will be part of that routine, until the keyword end is encountered. end, as the name implies, marks the end of the routine. All routines must be defined before being used. This example program loads the A register with the value 1 and then runs a loop that increments the value in the A register by 1 for every iteration until it reaches 10000, returns and halts the CPU:

routine: loop
radd A num 1
comp reg A num 10000
juin loop      # Jump to routine "loop" if the value in register A isn't equal to 10000
rtor           # Will be reached when the value in register A is equal to 10000
end

routine: entry
load A num 1
bran loop        # Jump to routine called "loop"
ctrl cpu halt    # Routine "loop" returns here when it encounters the "rtor" instruction
end
Detailed explanation
  1. In "entry": Loads the A register with the value 1
  2. In "entry": Jumps to a routine called "loop"
  3. In "loop": Add 1 to the value in the A register
  4. In "loop": Compare the value in the A register to 10000, set the eq_flag if true
  5. In "loop": If the eq_flag is not set, jump to a routine called "loop" (itself here), otherwise continue
  6. In "loop": "Return to origin" instruction returns to where the program came from, moving on from there
  7. In "entry": Send the CPU into the halt loop, stopping execution

Instructions

Now it gets interesting. Instructions are key to make the machine do things, so there are (will be) a lot of them

load

Explanation

load is used to load a value into a register. Which register is specified by the first argument, the value by the second. Examples:

load A num 7
load B hex H
load C lit 0x06AF

stor

Explanation

stor is used to store a value from the register specified by the first argument to the address specified in the second argument. It's also possible to store a registers value to a variable Examples:

stor A lit 0x56FA  # Stores the value in the A register to address 0x56FA (the 22266th address) in the memory
stor A num 22266
stor A var <variable> # Stores the value in the A register to the specified variable

jump

Explanation

jump is used to simply jump to a given address or routine. Examples:

jump lit 0x56FA    # Jumps to the address 0x56FA (the 22266th address) in the memory
jump num 22266     # You can also use a number directly

jump <routine>

juie

Explanation

juie is used just like jump with the slight difference that it only jumps to the specified address if the CPU's eq_flag is set. Examples:

juie lit 0x56FA    # Jumps to the address 0x56FA (the 22266th address) in the memory if the eq_flag is set
juie num 22266     # You can also use a number directly

juin

Explanation

juin is used just like jump with the slight difference that it only jumps to the specified address if the CPU's eq_flag is NOT set. Examples:

juin lit 0x56FA    # Jumps to the address 0x56FA (the 22266th address) in the memory if the eq_flag is NOT set
juin num 22266     # You can also use a number directly

bran

Explanation

bran is used just like jump with the slight difference that it saves the previous position to the stack, allowing the program to return to the previous position using rtor. Examples:

bran lit 0x56FA    # Jumps to the address 0x56FA (the 22266th address) in the memory
bran num 22266     # You can also use a number directly

brie

Explanation

brie is used just like bran with the slight difference of it being conditional, here if the equal flag is set. Example:

comp num 8 num 9
brie <routine>    # Will not jump to the specified routine

comp num 9 num 9
brie <routine>    # Will jump to the specified routine

brin

Explanation

brin is used just like bran with the slight difference of it being conditional, here if the equal flag is NOT set. Example:

comp num 8 num 9
brin <routine>    # Will jump to the specified routine

comp num 9 num 9
brin <routine>    # Will not jump to the specified routine

rtor

Explanation

rtor is used to return from a routine to the previous position. Example:

rtor    # This doesn't take any arguments

noop

Explanation

noop Simply makes the CPU do nothing for one cycle. Example:

noop    # Makes the CPU do nothing for one cycle

setv

Explanation

setv is used to set an address in the memory to the specified value. Examples:

setv lit 0x56FA hex U       # Sets the address 0x56FA (the 22266th address) in the memory to the ASCII representation of the character 'U'
setv num 22266 lit 0x0055   # You can also use a number or hex values directly

comp

Explanation

comp is used to compare two values. These values must not be bigger than 0xEFFF (61439). If those values are equal, the CPU's eq_flag will be set. The values to be compared can either be registers or specified directly. Examples:

comp lit 0x4000 num 8    # Compares the hexadecimal value 0x4000 with the decimal value 8
comp reg A num 8         # Compares the content of register A with the decimal value 8
comp reg A reg B         # Compares two registers

radd

Explanation

radd is used to increment a register's value by the following value. Examples:

radd A num 8      # Increases the value in the A register by 8
radd B hex 12     # Increases the value in the B register by 0x12 (18 in decimal)

rsub

Explanation

rsub is used to decrement a register's value by the following value. Examples:

rsub A num 8      # Decreases the value in the A register by 8
rsub B hex 12     # Decreases the value in the B register by 0x12 (18 in decimal)

rmul

Explanation

rmul is used to multiply a register's value by the following value. Examples:

rmul A num 8      # Multiplies the value in the A register by 8
rmul B hex 12     # Multiplies the value in the B register by 0x12 (18 in decimal)

rdiv

Explanation

rdiv is used to divide a register's value by the following value. Examples:

rdiv A num 8      # Divides the value in the A register by 8
rdiv B hex 12     # Divides the value in the B register by 0x12 (18 in decimal)

draw

Explanation

draw is a versatile instruction used to print things to the VM's monitor. It can be used to print str types, the content of registers or variables. It supports colored printing of str types. Currently available colors are red, green, blue, cyan and magenta. Examples:

draw str Hello^World! col green    # Prints a green "Hello World!" to the screen
draw str Hello^World!              # No color specification will default to white

draw reg A        # Prints the content of the A register
draw var value    # Prints the value of the variable "value"

ctrl

Explanation

ctrl is used to control the GPU and the CPU. Examples:

ctrl cpu halt     # Stops the CPU and execution of the program

ctrl gpu clear    # Clears the screen
ctrl gpu reset    # Resets the gpu
Commit count: 0

cargo fmt