Chapter 9 Using Macros

A “macro” is a symbolic name you give to a series of characters (a text macro) or to one or more statements (a macro procedure or function). As the assembler evaluates each line of your program, it scans the source code for names of previously defined macros. When it finds one, it substitutes the macro text for the macro name. In this way, you can avoid writing the same code several places in your program.

This chapter describes the following types of macros:

Text macros, which expand to text within a source statement

Macro procedures, which expand to one or more complete statements and can optionally take parameters

Repeat blocks, which generate a group of statements a specified number of times or until a specified condition becomes true

Macro functions, which look like macro procedures and can be used like text macros but which also return a value

Predefined macro functions and string directives, which perform string operations

Macro processing is a text-processing mechanism that is done sequentially at assembly time. By the end of assembly, all macros have been expanded and the resulting text assembled into object code.

This chapter shows how to use macros for simple code substitutions as well as how to write sophisticated macros with parameter lists and repeat loops. It also describes how to use these features in conjunction with local symbols, macro operators, and predefined macro functions.