Professional Documents
Culture Documents
JITHIN JACOB
LECTURER
Dept. Of CSE
MACE
ADAPTED FROM
3. MACRO EXPANSION
1. Macro definition
The two directive MACRO and MEND are used in macro
definition.
The first MACRO statement identifies the beginning of the
macron definition
MEND - end of macro definition
The name of the macro is followed by a list of parameters of
macro instruction
Each parameter begins with &
Between MACRO and MEND is the body of the macro. These
are the statements that will be generated as the expansion of the
macro definition.
syntax
MACRO
<name> [ parameter list]
-----------------------------
-----------------------------
----------------------------
<assembly language code>
MEND
Example:
MACRO // macro header statement ( indicate existence of macro)
SUM &X, &Y
LOAD &X
ADD &Y
STORE &X
MEND
2. MACRO INVOCATION
Used to call the MACRO
MACRO invocation statement gives the name of the macro
instruction being invoked and the actual parameters to be
used in expanding the macro
Entry # STATEMENT
26 SUM &X , &Y #1,#2
27 LOAD &x #1
28 ADD &Y #2
29 STORE &X #3
30 MEND
31
32
NAMTAB: FORMAT
SUM 26 2 3 0
ARGTAB : FORMAT
#1
M
#2 N
ADD M
#3
Data Structures Snapshot
DESIGN OF A ONE - PASS MACRO
PREPROCESSOR
PREPROCESSOR :Macro preprocessor is a software
which accepts an assembly language program that
consist of macro definition and macro calls and
converts it into an assembly language program with
out macro calls and macro expansion
Assembly lang. program macro preprocessor
ALP with out macros ASSEMBLER target
pgm
// macro processor inbuilt in assembler or closely
related to assembler
//one pass scan & expand in one step
Two pass scan first and expand when called
Design consist of 3 steps
EXPAND = OFF
Algorithm Pseudo Code
TYPES OF MACRO
3. RECURSIVE MACRO
Machine Independent Features
Concatenation of Macro
Parameters
Most macro processors allow parameters to
be concatenated with other character stings.
E.g., to flexibly and easily generate the
variables XA1, XA2, XA3, , or XB1,
XB2, XB3, A or B can be input as an
argument. We just need to concatenate X,
the argument, and the 1 , 2, 3 ..
together.
Concatenation Example
Macro definition using concatenation operator
MACRO
TOTAL &ID
LDA X&ID1
ADD X&ID2
ADD X&ID3
STA X&IDs
MEND
LDA XA1
ADD XA2
ADD XA3
STA XAS
Generation of Unique Labels
To generate unique labels for each macro
invocation, when writing macro definition, we
must begin a label with $.
During macro expansion, the $ will be replaced
with $xx, where xx is a two-character
alphanumeric counter of the number of macro
instructions expanded.
XX will start from AA, AB, AC,..
Unique Labels Macro Definition
Unique Labels Macro Expansion
Conditional Macro Expansion
So far, when a macro instruction is invoked, the
same sequence of statements are used to expand
the macro.
Here, we allow conditional assembly to be used.
Depending on the arguments supplied in the macro
invocation, the sequence of statements generated for a
macro expansion can be modified.
Conditional macro expansion can be very useful.
It can generate code that is suitable for a particular
application.
Conditional Macro Example
In the following example, the values of &EOR and &MAXLTH
parameters are used to determine which parts of a macro definition
need to be generated.
There are some macro-time control structures introduced for doing
conditional macro expansion:
IF- ELSE-ENDIF
WHILE-ENDW
Macro-time variables can also be used to store values that are used
by these macro-time control structures.
Used to store the boolean expression evaluation result
A variable that starts with & but not defined in the parameter list is treated
as a macro-time variable.
Macro time variable