Variables - gtrxAC/gxarch GitHub Wiki

The gxarch assembler has three different types of variables. Variables can be global (accessible from anywhere within that program, after it has been defined) or local to a block scope inside braces { ... }. They can be shadowed, so if two variables of the same name exist, one is global and one is local to the current scope, the local one is always used inside that scope.

Variables of different types cannot be mixed together, so for example an instruction that wants an address cannot receive a value. However, 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].

There are a few compile time instructions for managing variables. These are not actual instructions executed by the emulator.

Values

Single byte (8-bit, 0 to 255) values used to represent constants.

dat <value>, <value>, ...

Adds bytes to the final program. Each value can be a number or a variable containing a value. Each value must be separated by a comma.

val <name> <value>

Sets a variable called name to a value of value.

Addresses

Two-byte (16-bit, 0 to 65535) values used to represent memory addresses or larger constants.

datl <address>, <address>, ...

Adds addresses (2 byte values) to the final program. Similar to dat. Used for specifying the entry point of a program.

addr <name> <value>

Similar to val but for addresses.

Registers

Single byte (8-bit, but only 6 bits are used, 0 to 63) values used to represent registers.

reg <name> <register>

Sets a variable called name to a register value of register.

reg first %4
reg second %5
add [first] [second] first

is the same as

add [%4] [%5] %4

args <name>, <name>, ...

Assigns names to the argument registers.

vars <name>, <name>, ...

Assigns names to the function local registers.

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