|
|||||||||||
|
Technical Support On-Line Manuals Assembler Reference |
Assembler ReferenceMACRO and MEND
The Two directives are used to define a macro. The syntax is:
MACRO
{$where:
If you start any Within the macro body, parameters such as
Use In a macro that uses several internal labels, it is useful to define each internal label as the base label with a different suffix. Use a dot between a parameter and following text, or a following parameter, if a space is not required in the expansion. Do not use a dot between preceding text and a parameter. You can use the Macros define the scope of local variables. Macros can be nested.
; macro definition
MACRO ; start macro definition
$label xmac $p1,$p2
; code
$label.loop1 ; code
; code
BGE $label.loop1
$label.loop2 ; code
BL $p1
BGT $label.loop2
; code
ADR $p2
; code
MEND ; end macro definition
; macro invocation
abc xmac subr1,de ; invoke macro
; code ; this is what is
abcloop1 ; code ; is produced when
; code ; the xmac macro is
BGE abcloop1 ; expanded
abcloop2 ; code
BL subr1
BGT abcloop2
; code
ADR de
; code
Using a macro to produce assembly-time diagnostics:
MACRO ; Macro definition
diagnose $param1="default" ; This macro produces
INFO 0,"$param1" ; assembly-time diagnostics
MEND ; (on second assembly pass)
; macro expansion
diagnose ; Prints blank line at assembly-time
diagnose "hello" ; Prints "hello" at assembly-time
diagnose | ; Prints "default" at assembly-time
NoteWhen variables are also being passed in as arguments, use
of MACRO ; Macro definition m2 $a,$b=r1,$c ; The default value for $b is r1 add $a,$b,$c ; The macro adds $b and $c and puts result in $a MEND ; Macro end MACRO ; Macro definition m1 $a,$b ; This macro adds $b to r1 and puts result in $a LCLS def ; Declare a local string variable for | def SETS "|" ; Define | m2 $a,$def,$b ; Invoke macro m2 with $def instead of | ; to use the default value for the second argument. MEND ; Macro end
AREA codx, CODE, READONLY
; macro definition
MACRO
Return$cond
[ {ARCHITECTURE} <> "4"
BX$cond lr
|
MOV$cond pc,lr
]
MEND
; macro invocation
fun PROC
CMP r0,#0
MOVEQ r0,#1
ReturnEQ
MOV r0,#0
Return
ENDP
END
| ||||||||||
|
|||||||||||