User manual
ST Assembler-Linker ST assembler
Doc ID 11392 Rev 4 31/89
There is one further problem: because a macro may be called several times in the same
module, any labels defined in the macro will be duplicated. The LOCAL directive gets around
this problem:
For example:
getio MACRO
LOCAL loop
loop ld A,$C000
jra loop
MEND
This macro creates the code for a loop to await IO port at $C000 to go low. Without the
LOCAL directive, the label 'loop' would be defined as many times as the macro is called,
producing syntax errors at assembly time.
Because it's been declared LOCAL at the start of the MACRO definition, the assembler takes
care of it. Wherever it sees the label 'loop' inside the macro, it changes the name 'loop' to
'LOCXXXX' where XXXX is a hex number from 0000 to FFFF.
Each time a local label is used, XXXX is incremented. So, the first time the getio macro is
called, 'loop' is actually defined as 'LOC0', the second time as 'LOC1' and so on, each of
these being a unique reference name. The reference to 'loop' in the 'if' statement is also
detected and changed to the appropriate new local variable.
The directives in Ta ble 1 2 are very useful, in conjunction with macros:
4.5.2 Parameter substitution
The assembler looks for macro parameters after every space character. If you want to
embed a parameter, for example, in the middle of a label, you must precede the parameter
name with an ampersand '&' character, to make the parameter visible to the preprocessor.
For example, if we have a parameter called 'param'.,
dc.w param
It works as expected, but the ampersand is necessary on:
label¶m:nop
label¶m&_¶m:nop
Otherwise 'labelparam' would be left as a valid label name; If the macro parameter
'param' had the value '5', then 'label5' and 'label5_5' would be created.
Table 12. Some useful directives
Directive Usage
#IFB To implement macro optional parameters.
#IFDEF To test if a parameter is defined.
#IFLAB To test if a parameter is a label.
#IFIDN To compare a parameter to a given string.