TWO PASS
MACROPROCESSOR
DEFINITION
AND
ALGORITHM
CONTENTS
Specification of Problem
Specification of databases
Algorithm
Flowchart
SPECIFICATION OF PROBLEM
In Pass-I the macro definitions are searched
and stored in the macro definition table and
the entry is made in macro name table
In Pass-II the macro calls are identified and
the arguments are placed in the appropriate
place and the macro calls are replaced by
macro definitions.
SPECIFICATION OF DATABASES
Pass 1: The input macro source program.
The output macro source program to be used by Pass2.
Macro-Definition Table (MDT), to store the body of macro defns.
Macro-Definition Table Counter (MDTC), to mark next available
entry MDT.
Macro- Name Table (MNT) - store names of macros.
Macro Name Table counter (MNTC) - indicate the next available
entry in MNT.
Argument List Array (ALA) - substitute index markers for dummy
arguments before storing a macro-deff.
SPECIFICATION OF DATABASES
Pass 2: The input is from Pass1.
The output is expanded source to be given to
assembler.
MDT and MNT are created by Pass1.
Macro-Definition Table Pointer (MDTP), used to
indicate the next line of text to be used during macroexpansion.
Argument List Array (ALA), used to substitute macrocall arguments for the index markers in the stored
macro-defns
PASS I - ALGORITHM
Pass1 of macro processor makes a line-by-line scan over its
input.
Set MDTC = 1 as well as MNTC = 1.
Read next line from input program.
If it is a MACRO pseudo-op, the entire macro definition except
this (MACRO) line is stored in MDT.
The name is entered into Macro Name Table along with a
pointer to the first location of MDT entry of the definition.
When the END pseudo-op is encountered all the macro-defns
have been processed, so control is transferred to pass2
Pass 1
MDTC<-1
MNTC<-1
PASS I - FLOWCHART
Read next
source card
MACRO
pseudoop?
Write copy of
source card
END
pseudoop?
Read next
source card
Enter macro name and
current value of MDTC
in MNT entry number
MNTC
Read next
source card
MNTC <- MNTC + 1
Substitute
index
notation for
arguments
Prepare argument list array
Enter macro name card
into MDT
MDTC <- MDTC + 1
Go to Pass 2
Enter line into MDT
MDTC <- MDTC + 1
MEND
pseudoop?
PASS II - ALGORITHM
This algorithm reads one line of i/p prog. at a time.
for each Line it checks if op-code of that line matches
any of the MNT entry.
When match is found (i.e. when call is pointer called
MDTF to corresponding macro defns stored in MDT.
The initial value of MDTP is obtained from MDT index
field of MNT entry.
The macro expander prepares the ALA consisting of a
table of dummy argument indices & corresponding
arguments to the call.
PASS II - ALGORITHM
Reading proceeds from the MDT, as each successive
line is read, The values form the argument list one
substituted for dummy arguments indices in the macro
defn.
Reading MEND line in MDT terminates expansion of
macro & scanning continues from the input file.
When END pseudo-op encountered , the expanded
source program is given to the assembler
PASS II - FLOWCHART
Pass 2
Read next
source card
(copied by
pass 1)
Search MNT for match
with operation code
MACRO
name
found?
Write into
expanded
source card
file
No
Yes
END
pseudoop?
MDTP <- MDT index
from MNT entry
Yes
Supply expanded
source file to
assembler
processing
Set up argument list
array
MDTP <- MDTP + 1
Get line from MDT
Substitute arguments
from macro call
Yes
MEND
pseudoop?
No
Write
expanded
source card
No