/Xasm

A dumbed-down version of assembly with REPL support

Primary LanguageRust

Xasm

A dumbed-down version of assembly with REPL support

Issues

Due to jmp being its own function that waits for execution to finish, recursive loops will eventually result in a stack overflow.
To get around this, use the LOOP and LOOPNOINC instructions for looping.

Usage

Registers

Register Usage
R0-12 General purpose registers
P0-12 Paramater registers, for passing arguments to functions/syscalls
RET0-12 Return registers, for returning values from functions/syscalls
L0 Loop register, defines how many times to jmp to a label

Instructions

Instruction Usage
PUSH register Pushes register onto the stack
POP register Pops the top value off the stack and into register
MOV register1 value/register2 Copies the value of value/register2 into register1
INC register Increments the value in register
DEC register Decrements the value in register
ADD register1 value/register2 Adds value/register2 to register
SUB register1 value/register2 Subtracts value/register2 from register
MUL register1 value/register2 Multiplies register1 by value/register2
DIV register1 value/register2 Divides register1 by value/register2
XOR register1 value/register2 Performs an XOR on register1 with value/register2
CMP register1 value/register2 Compares value/register2 to register and sets equal_flag, lesser_flag & greater_flag accordingly
JMP label Calls a builtin or user defined function
JE label Calls label only if equal_flag is true
JNE label Calls label only if equal_flag is false
JZ label Calls label only if zero_flag is true
JNZ label Calls label only if zero_flag is false
JG, JGE, JL, JLE label Jump greater, Jump greater than or equal, Jump less than, Jump less than or equal
SETG, SETGE, SETL, SETLE register Sets register to a boolean based on the lesser, greater and equal flags
LOOP label Calls label until L0 is 0, decrementing it each loop
LOOPNODEC label Calls label L0 times without decrementing it, much faster than LOOP

Builtin functions

Function Usage
print prints P0
printline prints P0 with a newline
input Fetches user input and places it in RET0
debug Prints out the entire program layout - functions, register states etc
exit Exits the program with exit code P0