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.

Argument types

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.

Instructions

0 nop No operation

Does nothing.

1 set <reg> <val> Set

Sets a register to a value.

2 ld <reg> <addr> Load

Loads a value from a memory address to a register.

3 st <reg> <addr> Store

Stores a value from a register to a memory address. Only RAM and SRAM (addresses 0xE000 to 0xFFFF) can be accessed by this instruction.

4 add <val> <val> <reg> Add

5 sub <val> <val> <reg> Subtract

6 mul <val> <val> <reg> Multiply

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).

7 div <val> <val> <reg> Divide

8 mod <val> <val> <reg> Division remainder

Like add, sub, and mul, but the output is 8-bit, so the resH register is not changed.

9 and <val> <val> <reg> Bitwise AND

10 or <val> <val> <reg> Bitwise OR

11 xor <val> <val> <reg> Bitwise XOR

Performs a bitwise operation on two numbers and saves the result in the specified register.

12 eq <val> <val> <reg> Equal

13 lt <val> <val> <reg> Less than

14 gt <val> <val> <reg> Greater than

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.

15 eqj <val> <val> <addr> Jump if equal

16 ltj <val> <val> <addr> Jump if less than

17 gtj <val> <val> <addr> Jump if greater than

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.

18 eqc <val> <val> <addr> Call function if equal

19 ltc <val> <val> <addr> Call function if less than

20 gtc <val> <val> <addr> Call function if greater than

Like eqj, ltj, and gtj, but calls a function instead of just jumping.

21 arg <val> Argument

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.

22 jmp <addr> Jump

Jumps to a location in the ROM (addresses 0x0000 to 0x8000).

23 cj <reg> <addr> Conditional jump

Jumps to a location in the ROM if the value in the specified register is not 0.

24 call <addr> Call function

Calls a function at a location in the ROM (addresses 0x0000 to 0x8000).

25 cc <reg> <addr> Conditional call

Calls a function at a location in the ROM if the value in the specified register is not 0.

26 ret Return

Returns back from a function to where it was called. This does not change the return value register.

27 retv <val> Return with value

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.

28 sys <val> Syscall

Performs a system call with the specified number ID.

⚠️ **GitHub.com Fallback** ⚠️