SPNU118Z September 1995 – March 2023 66AK2E05 , 66AK2H06 , 66AK2H12 , 66AK2H14 , AM1705 , AM1707 , AM1802 , AM1806 , AM1808 , AM1810 , AM5K2E04 , OMAP-L132 , OMAP-L137 , OMAP-L138 , SM470R1B1M-HT , TMS470R1A288 , TMS470R1A384 , TMS470R1A64 , TMS470R1B1M , TMS470R1B512 , TMS470R1B768
You can define a macro anywhere in your program, but you must define the macro before you can use it. Macros can be defined at the beginning of a source file or in a .copy/.include file (see Copy Source File); they can also be defined in a macro library. For more information about macro libraries, see Section 6.4.
Macro definitions can be nested, and they can call other macros, but all elements of the macro must be defined in the same file. Nested macros are discussed in Section 6.9.
A macro definition is a series of source statements in the following format:
macname | .macro [parameter1] [, ... ,parametern ] |
model statements or macro directives | |
[.mexit] | |
.endm |
macname | names the macro. You must place the name in the source statement's label field. Only the first 128 characters of a macro name are significant. The assembler places the macro name in the internal opcode table, replacing any instruction or previous macro definition with the same name. |
.macro | is the directive that identifies the source statement as the first line of a macro definition. You must place .macro in the opcode field. |
parameter1, parametern |
are optional substitution symbols that appear as operands for the .macro directive. Parameters are discussed in Section 6.3. |
model statements | are instructions or assembler directives that are executed each time the macro is called. |
macro directives | are used to control macro expansion. |
.mexit | is a directive that functions as a goto .endm. The .mexit directive is useful when error testing confirms that macro expansion fails and completing the rest of the macro is unnecessary. |
.endm | is the directive that terminates the macro definition. |
If you want to include comments with your macro definition but do not want those comments to appear in the macro expansion, use an exclamation point to precede your comments. If you do want your comments to appear in the macro expansion, use an asterisk or semicolon. See Section 6.7 for more information about macro comments.
The following example shows the definition, call, and expansion of a macro.
Macro definition: The following code defines a macro, add3, with four parameters:
1 *
2
3 * add3
4 *
5 * ADDRP = P1 + P2 + P3
6
7 add3 .macro P1, P2, P3, ADDRP
8
9 ADD ADDRP, P1, P2
10 ADD ADDRP, ADDRP, P3
11 .endm
Macro call: The following code calls the add3 macro with four arguments:
12
13 00000000 add3 R1, R2, R3, R0
Macro expansion: The following code shows the substitution of the macro definition for the macro call. The assembler substitutes R1, R2, R3, and R0 for the P1, P2, P3, and ADDRP parameters of add3.
1
1 00000000 E0810002 ADD R0, R1, R2
1 00000004 E0800003 ADD R0, R0, R3