Sie sind auf Seite 1von 12

MACROS

Macro definition and


invocation
A macro is a block of text that has been
given a name. when MASM encounters the
name during assembly, it inserts the block
into the program. The syntax of macro is:
MACRO d1,d2,…dn
Statements
ENDM
macro_name is the user
supplied name for macro. The
pseudo-op macro & endm
indicate the beginning & end of
macro definition; d1,d2…..dn is
an optional list of dummy
argument used by the macro.
ILLEGAL MACRO
INVOCATION
There are often restrictions on the arguments
for a macro.
Arguments in movw macro must be:
Memory, Word, 16_bit register.
MOV AX,1ABCh
Generates the code
PUSH 1ABCh
POP AX
An immediate data push is
illegal for 8086/8088 this
results in an assembly
Example :-
MOVW MACRO WORD1,WORD2
;arguments must be
memory,words,16_bit register
PUSH WORD2
POP WORD1
ENDM
RESTORING
REGISTER
 Good programming practice requires that a procedure should
restore the register it uses, unless they contain output values.
The same is usually true for macros.
EXCH MACRO WORD1, WORD2
PUSH AX
MOV AX, WORD1
XHG AX,WORD2
MOV WORD1,AX
POP AX
ENDM
MACRO EXPANSION IN .LST FILE

.LST is a file that can be generated


when program is assembled.
It shows assembly code and the
corresponding machine code,
addresses of variables & other
information about the program.
.LST shows how macros are
expanded.
.LST FILE OPTIONS
After .SALL (suppress all),the
assembly code in a macro expansion
is not listed. You might want to use
this option for large macros, or if there
are a lot of macros invocations.
After .XALL only those source lines
that generates code or data are
listed…for e.g comment lines are not
listed. This is default options.
After .LALL (list all) all source lines
are listed, expect those start with(;;).
FINDING ASSEMBLY ERRORS
If MASM finds an error during
macro expansion, it indicates
an error at the point of the
macro invocation; however, its
more likely that the problem is
within the macro itself.
To find the mistake you need
to inspect the macro
expansion in .LST file.
LOCAL
LABELS
A macro with a loop r decision structure
contains one or more labels.
Macro invoked more than once , a duplicate
label appears, resulting in an assembly error.
This problem can b avoided by using local
labels
To declare them we use Local pseudo_op
SYNTAX: LOCAL list_of_labels
• List_of_lables is a list of
labels separated by
commas(,).
Every time the macro is expanded,
MASM assigns different symbols to
the labels in list.
The LOCAL directive must appear
on the next line after the MACRO
statement; not even a comment can
precede it.
PAGE:263,264

MACROS THAT
INVOKE OTHER
MACROS:

Das könnte Ihnen auch gefallen