Instruction Set - ezasm-org/ezasm GitHub Wiki
Arithmetic Instructions
There are instructions to do simple arithmetic.
Over Integers:
add output input1 input2: addinput1andinput2and store result inoutputsub output input1 input2: subtractinput2frominput1and store result inoutputmul output input1 input2: multiplyinput1andinput2and store result inoutputdiv output input1 input2: divideinput1byinput2and store result inoutputmod output input1 input2: store the remainder of dividinginput1byinput2inoutputinc input-output: incrementinput-outputby 1dec input-output: decrementinput-outputby 1
Over Floats:
The operations over floats are much the same in terms of functionality:
addf output input1 input2subf output input1 input2mulf output input1 input2divf output input1 input2modf output input1 input2incf input-outputdecf input-output
Conversion Instructions
ftoi output input: store the conversion ofinputto an integer inoutputitof output input: store the conversion ofinputto a float inoutput
Note: Division by zero in float instructions will yield NaN if and only if the numerator is also zero. Otherwise, division by zero will result in an error.
Using any of the integer instructions on floats, or any float instructions on integers will cause undefined behavior. When programming, pay special attention to keep track of what registers contain which types.
Additionally, all non-conversion instructions listed in this section are guaranteed to produce a result in the same domain as their inputs when used as intended. This means that all operations over integers will produce an integer, and all operations over floats will produce a float.
ftoi will result in an error if the input is NaN.
The LO and HI registers are updated only during the usage of the mul instruction. LO will always store the same result as what is to be stored in output. On overflow, HI will store the most-significant half of the bits of the product, depending on the word size.
Bitwise Instructions
There are instructions to do simple bitwise arithmetic.
and output input1 input2or output input1 input2xor output input1 input2not output inputsll output input1 shift: "shift left logical" instructionsrl output input1 shift: "shift right logical" instructionsra output input1 shift: "shift right arithmetic" instruction
Note: for all of the shift instructions, there are safeguards in place to prevent improper usage. Any negative shift or shift greater than the word size will default to a result of 0. In the case of sra, these results will be sign-extended properly.
Function Instructions
There are instructions to do with function calls.
j input: jumps to the givenprogram counterjump input: jumps to the givenprogram counterjal input: stores the currentreturn address $raandfile identifier $fidonto the stack and then jumps to the givenprogram counter- increments the stack pointer by
2 * word size
- increments the stack pointer by
call input: stores the currentreturn address$raandfile identifier $fidonto the stack and then jumps to the givenprogram counter- increments the stack pointer by
2 * word size
- increments the stack pointer by
return: returns to the currently storedreturn addressand then pops the oldreturn address $raandfile identifier $fidoff of the stackexit input: stores the input to$r0and terminates the programimport "relative/path/to/file": attempts to import code from the file at the given relative path- labels within imported files can only be accessed using
call/jal - looks for a file using absolute path if running anonymously
- produces an error if the file is unable to be read, contains invalid code, or contains a label which has already been defined
- labels within imported files can only be accessed using
Note: Jump instructions will throw an InvalidProgramCounterException when attempting to jump to an address outside the current program's code.
Branching Instructions
There are instructions to do with conditional branches.
blt input1 input2 input3: jumps toinput3ifinput1is less thaninput2ble input1 input2 input3: jumps toinput3ifinput1is less than or equal toinput2bgt input1 input2 input3: jumps toinput3ifinput1is greater thaninput2bge input1 input2 input3: jumps toinput3ifinput1is greater than or equal toinput2beq input1 input2 input3: jumps toinput3ifinput1is equal toinput2bne input1 input2 input3: jumps toinput3ifinput1is not equal toinput2
Comparison Instructions
There are instructions to do with conditional branches.
slt input1 input2 input3: stores a1ininput1ifinput2is less thaninput3,0otherwisesle input1 input2 input3: stores a1ininput1ifinput2is less than or equal toinput3,0otherwisesgt input1 input2 input3: stores a1ininput1ifinput2is greater thaninput3,0otherwisesge input1 input2 input3: stores a1ininput1ifinput2is greater than or equal toinput3,0otherwiseseq input1 input2 input3: stores a1ininput1ifinput2is equal toinput3,0otherwisesne input1 input2 input3: stores a1ininput1ifinput2is not equal toinput3,0otherwise
Memory Instructions
Basic memory functionality.
push input: stores the given value onto the stack and then decrements (grows) thestack pointerpop input: retrieves a value from the stack and then increments (shrinks) thestack pointerload output input: loads the value at the given address into the given outputstore output input: stores the value given at the output addressalloc output input: allocatesinputbytes and returns a pointer to the allocationmalloc output input: dynamically allocatesinputbytes and returns a pointer to the allocationfree input: free dynamically allocated memory (viamalloc) without modifyinginputmove output input: move the contents ofinputtooutput
Note: Memory instructions will throw a SimulationAddressOutOfBoundsException when attempting to read or write to an address outside of the program's memory space. See: Structure
Terminal Instructions
Terminal input and output.
-
printi input: prints the given input to the terminal as an integer -
printf input: prints the given input to the terminal as a float -
printc input: prints the given input to the terminal as an ASCII character -
prints input1 input2: prints up toinput2characters of the given string address to the terminal until a null terminator is reached -
prints input1: prints the given string address to the terminal until a null terminator is reached -
readi output: reads the given input to the terminal as an integer -
readf output: reads the given input to the terminal as a float -
readc output: reads the given input to the terminal as an ASCII character -
reads input1 input2: reads from the terminal a string of up toinput2length into the address ofinput1 -
reads input1: reads from the terminal a string into the address ofinput1 -
readln input1 input2: reads from the terminal a string of up toinput2length into the address ofinput1until a newline character -
readln input1: reads from the terminal a string into the address ofinput1until a newline character