Next: , Previous: , Up: Using the Assembler Preprocessor   [Contents][Index]


5.14.4 Defining Macros

A macro definition looks like this:

name    macro   arg1, arg2, ...
        text
        end     macro

The above block of code defines macro name with arguments arg1, arg2, ... A macro may have no arguments at all. Names of macro arguments work as names of local symbols that can be used within a macro.

If a macro has a long list of arguments, then the list can be split into multiple lines. To indicate that a line of arguments list is continued on the next line, terminate a line, which is continued, with a comma after the name of an argument. This is shown in the following example:

mac1    macro   arg1, arg2, arg3, arg4,
                arg5, arg6, arg7, arg8
        ...
        end     macro

Below is an example of a macro that can represent a state linked to the other state in a chain of state transitions:

g1      macro   id, ll

s##id:  stt     #id
        regst                   ; register passing the state
        jmp     ll

        end     macro

Macro definitions cannot be nested. However, a macro can expand another macro, which expands another macro, and so on. The maximum supported nesting level of macro expansions is equal to 65535.

To expand macro name defined earlier in source text and use arg1, arg2, … for values of macro arguments, write a line like this:

        name    arg1, arg2, ...

The name of an expanded macro must be written on a separate line. Such a line must begin with at least one whitespace character followed by the name of the macro or must begin with a location label definition followed by at least one whitespace character and that name. No substitutions of symbol names with symbol values are performed in names of macros to expand. However, such substitutions are performed in values of macro arguments. After substituting, the value of every macro argument must reduce either to verbatim text, which does not contain commas, or to a string literal.

If a macro is expanded using a long list of arguments, then the list can be split into multiple lines. To indicate that a line of arguments list is continued on the next line, terminate a line, which is continued, with a comma after the value of an argument. This is shown in the following example:

        mac1    "alpha", 0.1, "beta",  0.2,
                "gamma", 0.3, "delta", 0.4

Next: , Previous: , Up: Using the Assembler Preprocessor   [Contents][Index]