Programming applications frequently involve the coding of a repeated pattern or group of instructions. Some patterns contain variable entries which change for each repetition of the pattern. Others are subject to conditional assembly for a given occurrence of the instruction group. In either case, macros provide a shorthand notation for handling these instruction patterns. Having determined the iterated pattern, the programmer can, within the macro, designate selected fields of any statement as variable. Thereafter, by invoking a macro, the programmer can use the entire pattern as many times as needed, substituting different parameters for the designated variable portions of the statements.
When the pattern is defined, it is given a name. This name becomes the mnemonic by which the macro is subsequently invoked (called). If the name of the macro is the same as an existing Assembler directive or mnemonic opcode, the macro replaces the directive or mnemonic opcode, and a warning is issued. The warning can be avoided by the use of the RDIRECT d irective, which is used to remove entries from the Assembler's directive and mnemonic tables. If directives or mnemonics are removed from the Assembler's tables, then no warning is issued when the Assembler processes macros whose names are the same as the removed directive or mnemonic entries.
The macro call causes source statements to be generated. The generated statements may contain substitutable arguments. The statements produced by a macro call are relatively unrestricted as to type. They can be any processor instruction, almost any Assembler directive, or any previously-defined macro. Source statements resulting from a macro call are subject to the same conditions and restrictions that are applied to statements written by the programmer.
To invoke a macro, the macro name must appear in the operation code field of a source statement. Any arguments are placed in the operand field. By suitably selecting the arguments in relation to their use as indicated by the macro definition, the programmer causes the Assembler to produce inline coding variations of the macro definition.
The effect of a macro call is to produce inline code to perform a predefined function. The code is inserted in the normal flow of the program so that the generated instructions are executed with the rest of the program each time the macro is called.
An important feature in defining a macro is the use of macro calls within the macro definition. The Assembler processes such nested macro calls at expansion time only. The nesting of a macro definition within another definition is permitted. However, the nested macro definition is not be processed until the primary macro is expanded. The macro must be defined before its appearance in a source statement operation field.