Part three introduced the notion of constants, but ObjAsm also supports variables. As the name implies, variables can change their value during the course of assembly. They can also handle more than just numeric values.
Variables support three different data types: numeric values (as per constants), boolean values (useful for controlling conditional assembly), and string values.
Variables can also be ‘local’ or ‘global’. Global variables are visible throughout the program, while local variables are restricted to just the current macro invocation.
The following directives are used to declare variables and set their values:
Data type | Declare global variable | Declare local variable | Set value |
---|---|---|---|
Numeric | GBLA | LCLA | SETA |
Boolean | GBLL | LCLL | SETL |
String | GBLS | LCLS | SETS |
For example:
GBLS ModuleName ModuleName SETS "Awesome" GBLA Version Version SETA 123 GBLL Debug Debug SETL {TRUE}
Note that for the SET directives, the variable name must appear at the start of the line.
Variables can be referenced directly using their name, the same as symbolic constants. E.g.:
SWI_GetVersion STR LR,[R13,#-4]! [ Debug SWI XOS_WriteS = "SWI_GetVersion called", 13, 10, 0 ALIGN ] MOV R0, #Version LDR PC,[R13],#4 Module_Help = ModuleName :CC: " is really awesome", 13, 10, 0
There are a number of built in variables which have special values. The most frequently used ones are:
Variable | Value |
---|---|
{TRUE} |
A boolean variable that has the value ‘true’ |
{FALSE} |
A boolean variable that has the value ‘false’ |
{PC} or . |
The address of the current location within the program (n.b. unlike the PC register, this does not have an 8 byte offset) |
{VAR} or @ |
The value of the storage map location counter (see part 3) |