Showing changes from revision #1 to #2:
Added | Removed | Changed
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
It’s also possible to prefix variable names with $
to force their expansion within contexts where variable expansion normally wouldn’t take place. This is mostly used for the following situations:
Module_Help = "$ModuleName is really awesome", 13, 10, 0
To use a literal $
within a string (for example as part of a system variable name) you need to use $$
otherwise you run the risk of accidental variable expansion.
This is commonly seen in macros, for example the (simplified) AddSWI macro seen below. Note the use of .
to terminate the variable name, allowing the expanded value to be concatenated with the following _
.
GBLS SWIClass MACRO AddSWI $SWIName $SWIClass._$SWIName # 1 MEND SWIClass SETS "MyModule" ^ &12340 AddSWI Foo AddSWI Bar AddSWI Wibble
The above will expand to the following, allowing easy declaration of symbolic constants for SWI numbers (note that the real AddSWI macro also defines constants for the X forms of the SWIs)
^ &12340 MyModule_Foo # 1 MyModule_Bar # 1 MyModule_Wibble # 1
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 |
ObjAsm has the WHILE
and WEND
directives, which operate in the same manner as WHILE loops in BASIC. You can place almost anything you want inside a while loop, and you can include while loops inside macro definitions (the loop will be evaluated when the macro is invoked), making them a very powerful tool.
GBLA count count SETA 0 WHILE count < 5 DCD count count SETA count+1 WEND
→
DCD 0 DCD 1 DCD 2 DCD 3 DCD 4