SPRU513Y August 2001 – June 2022 SM320F28335-EP
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 7.5.
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 7.10.
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 7.4. |
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 7.8 for more information about macro comments.
The following example shows the definition, call, and expansion of a macro.