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.
Single byte (8-bit, 0 to 255) values used to represent constants.
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.
Sets a variable called name
to a value of value
.
Two-byte (16-bit, 0 to 65535) values used to represent memory addresses or larger constants.
Adds addresses (2 byte values) to the final program. Similar to dat
. Used for specifying the entry point of a program.
Similar to val
but for addresses.
Single byte (8-bit, but only 6 bits are used, 0 to 63) values used to represent registers.
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
Assigns names to the argument registers.
Assigns names to the function local registers.