Professional Documents
Culture Documents
Unit 3 Macro1
Unit 3 Macro1
Unit 3 Macro1
MEND;
Macro: Example #1
Write a macro to increment the value of
a variable.
The following sequence of instructions is
used to increment the value in a
memory word by a constant.
1. Move the value from the memory word into a
machine-register.
2. Increment the value in the machine register.
3. Move the new value into the memory word.
Macro: Example #1
Macro definition to increment the value
of a variable.
MACRO
INCR &MEM_VAL, &INCR_VAL, ®
MOV ®, &MEM_VAL INCR is macro name;
MEM_VAL, INCR_VAL, REG
ADD ®, &INCR_VAL are formal parameters.
MEM_VAL is the value to be
MOV &MEM_VAL, ® incremented; INCR_VAL is
the incremental value and
MEND; REG is the register to be
used for holding temporary
values.
Macro Call
The macro is called by writing macro
name followed by actual parameters if
any.
The INCR macro can be called as
INCR A, B, AX
Macro Call Contd..
Macro call leads to macro expansion.
During macro expansion, the macro call
statement is replaced by a sequence of
assembly statements.
Each expanded statement is marked
with a “+” preceding its label field to
distinguish it from original program
statements.
Macro Expansion
&<EV name>
where <EV name> is an ordinary string.
&I SET 0
MEND;