Instructions - gtrxAC/gxarch GitHub Wiki
gxarch is designed to have few instructions compared to other instruction sets, but still be somewhat easy to use. There are currently 29 instructions. Due to the instruction encoding, there cannot be more than 32 instructions. Graphics and sound related instructions are grouped into syscalls. Each instruction also takes 3 or less arguments.
There are three types of instruction arguments:
-
reg
: Register. Most instructions operate on registers, load/store are used to access the main memory. Takes one byte. -
val
: Immediate value. This is a constant value that is directly part of the instruction. -
addr
: Memory address. Takes two bytes, in little endian order.
If an instruction wants a value or address but you want to read a register instead of using a constant value, you can put the register in [brackets]
. If a [register]
is used in place of an address, the high byte of the address is read from register
and the low byte is read from register + 1
.
Also see Variables.
Does nothing.
Sets a register to a value.
Loads a value from a memory address to a register.
Stores a value from a register to a memory address. Only RAM and SRAM (addresses 0xE000
to 0xFFFF
) can be accessed by this instruction.
Performs an arithmetic operation on two numbers. The inputs are 8-bit, but the output is 16-bit, where the low byte is stored in the specified register, and the high byte is stored in resH
(register %63
).
Like add
, sub
, and mul
, but the output is 8-bit, so the resH
register is not changed.
Performs a bitwise operation on two numbers and saves the result in the specified register.
Performs a comparison on two numbers and saves the result in the specified register (1 if true, 0 if false). These are usually only needed if you want to do multiple comparisons with and
and or
instructions.
Jumps to a location in the ROM (addresses 0x0000
to 0x8000
) if the comparison returns true. These are the same as eq/lt/gt val1 val2 somereg
cj somereg addr
, except a register doesn't have to be used to hold the comparison's result.
Like eqj
, ltj
, and gtj
, but calls a function instead of just jumping.
Passes an argument to the next called function or system call. These arguments can be accessed by the next called function with the argument registers. Up to 8 arguments can be passed at a time by running this instruction multiple times (doesn't have to be consecutive, there can be other instructions in between). In assembly, multiple arg
instructions can be written as one by giving it multiple arguments separated by commas: arg <val>, <val>, ...
Note: instructions can receive three different types of arguments but functions can only receive values.
Jumps to a location in the ROM (addresses 0x0000
to 0x8000
).
Jumps to a location in the ROM if the value in the specified register is not 0.
Calls a function at a location in the ROM (addresses 0x0000
to 0x8000
).
Calls a function at a location in the ROM if the value in the specified register is not 0.
Returns back from a function to where it was called. This does not change the return value register.
Returns back from a function to where it was called, and sets rVal
(register %48
) to the specified value. set rVal 1
ret
is the same as retv 1
.
Performs a system call with the specified number ID.