The macros that a program invokes can be stored in a file.
This makes it possible to create a library file of useful
macros and use it using the INCLUDE
For example, suppose the file's name is MACROS, on
a disk in drive A. When the assembler encounters the pseudo-op
in a program, it copies all the macro definitions from the file
MACROS into the program at the position of the INCLUDE statement.
| Position of INCLUDE Statement
The INCLUDE statement may appear anywhere in the program,
as long as it precedes the invocation of its macros.
Examples of Useful Macros
The following are examples of macros that are useful
to have in a macro library.
|Example: Write a macro to return to DOS.|
MOV AH, 4CH
The macro invocation is DOS_RTN
|Example: Write a macro to display a carriage return
and line feed.|
MOV AH, 2
MOV DL, 0DH
MOV DL, 0AH
The macro invocation is NEW_LINE
|Example: Write a macro to display a character
string such that the string is a macro parameter.|
DISP_STR MACRO STRING
LOCAL START, MSG
; save registers
MSG DB STRING, '$'
MOV AX, CS
MOV DS, AX
MOV AH, 9
LEA DX, MSG
; restore registers
Sample invocation: DISP_STR "This is a string"
When the DISP_STR macro is invoked, the string argument replaces
the STRING parameter. Because the string is being stored in
the code segment, CS must be moved to DS.
Using a Macro Library
The preceding macros have been placed in file MACROS. In
the following example, we will show how to use a macro
library in a program.
|Example: Write a program that uses the macro
library MACROS to display a message, go to a new line, and
display another message.|
DISP_STR "This is the first line"
DISP_STR "This is the second line"