Macros
Macros
Macros are just like procedures, but not really. Macros look like
procedures, but they exist only until your code is compiled, after
compilation all macros are replaced with real instructions. If you
declared a macro and never used it in your code, compiler will
simply ignore it. emu8086.inc is a good example of how macros
can be used, this file contains several macros to make coding
easier for you.
Macro definition:
name MACRO
[parameters,...]
<instructions>
ENDM
MOV AX, p1
MOV BX, p2
MOV CX, p3
ENDM
ORG 100h
MyMacro 1, 2, 3
MyMacro 4, 5, DX
RET
When you want to use a procedure you should use CALL instruction,
for example:
CALL MyProc
When you want to use a macro, you can just type its name. For
example:
MyMacro
To pass parameters to macro, you can just type them after the macro
name. For example:
MyMacro 1, 2, 3
To mark the end of the procedure, you should type the name of the
procedure before the ENDP directive.
MyMacro2 MACRO
LOCAL label1, label2
CMP AX, 2
JE label1
CMP AX, 3
JE label2
label1:
INC AX
label2:
ADD AX, 2
ENDM
ORG 100h
MyMacro2
MyMacro2
RET