Professional Documents
Culture Documents
Problem Statement
Design suitable data structures and implement first pass of a two-pass Macro
processor.
Theory:
• Assembler is a program for converting instructions written in low-level
assembly code into relocatable machine code and generating along
information for the loader
• It generates instructions by evaluating the mnemonics in operation field and
find the value of symbol and literals to produce machine code
• A Macro instruction is the notational convenience for the programmer
• For every occurrence of macro, the whole macro body or macro block of
statements gets expanded in the main source code
• Thus, Macro instructions make writing code more convenient
• Macro represents a group of commonly used statements in the source
programming language
• Macro Processor replaces each macro instruction with the corresponding
group of source language statements. This is known as the expansion of
macros
• Using Macro instructions programmer can leave the mechanical details to be
handled by the macro processor
• Macro Processor designs are not directly related to the computer
architecture on which it runs
• Macro Processor involves definition, invocation, and expansion
Algorithm:
• The very first step in the 1st pass of macro processor is import the .asm file
containing the macro code
• This code will be first checked for comments if any. Comments encountered
will be eliminated for further processing
• The next step to be executed in the macro processor is generating
intermediate code for the given assembly code
• The next part is to expand the macros to create Macro definition table (MDT)
which is an important element in the 2-pass macro processor
• On basis of MDT, the Macro name table is to be generated which has the
index on macros in the code and the macro names. Also, the number of
arguments is recorded in the table
• The macro name table and macro definition table contribute to formal v/s
positional parameters and actual v/s positional parameter for every macro
Code:
def assignEnd(unid,ind):
for i in MNT:
if i.uId == unid:
i.endInd =ind
break
MNT = []
ForPos = []
def addForPosParameters(paraList,mac):
i=0
table=[]
while(i<paraList.__len__()):
posi = "#"+str(i+1)
if(i!=paraList.__len__()-1):
paraList[i] = paraList[i][:-1]
table.append((paraList[i],posi))
i+=1
mac.ForPos = table
ForPos.append([mac.name,table])
def addToDef(line,m):
k=0
while(k<line.__len__()):
for var in m.ForPos:
if line[k].find(var[0]) != -1:
line[k] = line[k].replace(var[0],var[1])
k+=1
MDT.append(line)
definationMode = False
pointer =1
MNT =[]
MDT=[]
ForPos = []
uid=0
elif definationMode:
if paraLn>0:
addToDef(line,m)
else:
MDT.append(line)
pointer +=1
Input File:
Output:
Conclusion:
1. The first pass of 2 pass macro processor generates some important data
structures like MDT, MNT and intermediate code. Also, the actual v/s
positional parameter list and the formal v/s positional parameter list is
obtained.
2. The 1st pass also is significant for expansion of macros to execute the
instructions in the code one by one serially.
3. Also, the comments are eliminated in the pass.