Registers - gtrxAC/gxarch GitHub Wiki

gxarch has 64 registers, from 0 to 63. The registers can be thought of as 64 bytes of "scratch RAM" or "fast RAM" that can be accessed by any instruction without having to load or store. The registers are divided into a few sections:

0 - 31 General purpose

The first 32 registers are not reserved for any specific purpose and can be used for anything. These are most often used for variables with a short life span, such as results of quick calculations. Commonly used variables can also be kept here, for example the player's position or score in a game. The standard library does not use these registers, and other common utility functions should use argument/local registers instead.

32 - 39 Function arguments

Arguments given to the current function using the arg instruction. This works like a stack, each function call gets its own arguments and functions cannot access arguments of other functions.

main:
	arg 1, 2
	js function
	; ...

function: {
	args a, b

	; This function gets arguments %32 = 1 and %33 = 2
	; The 'args' instruction allows them to be referred to as 'a' and 'b'.
	; ...
}

40 - 47 Function locals

These registers are used for holding temporary variables in a function. They also work like a stack.

function: {
	vars a, b, c

	; This function has its own values for registers %40 to %47.
	; These values cannot be accessed by other functions.
	; The 'vars' instruction allows them to be referred to as 'a', 'b', and 'c'.
	; ...
}

48 - 63 Reserved

These registers are reserved for internal values, such as user input.

Note: Values related to button/key presses indicate how many frames the button has been pressed for, 0 if not pressed. If they reach 255, they will not overflow, they stay at 255.

  • 48 (rVal): function return value, set with the retv instruction
  • 49 (mouseX): mouse X position, 0 to 191
  • 50 (mouseY): mouse Y position, 0 to 159
  • 51 (mouseL): mouse left button
  • 52 (mouseR): mouse right button
  • 53 (kUp): up key, bound to up arrow and W
  • 54 (kDown): down key, bound to down arrow and S
  • 55 (kLeft): left key, bound to left arrow and A
  • 56 (kRight): right key, bound to right arrow and D
  • 57 (kAct1): action key 1, bound to J
  • 58 (kAct2): action key 2, bound to K
  • 59 (kAct3): action key 3, bound to L
  • 60-61 (clearX, clearY): clear color X/Y, one pixel from the tileset at this location is taken and its color will be the screen background color.
  • 62 (rand): random number
  • 63 (resH): high byte of arithmetic result (add, sub, mul), also known as the overflow register