0 ratings0% found this document useful (0 votes) 15 views8 pagesSPOS Lab Assignment 2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Aim: Design suitable data structures and implement pass-I of a two-pass macro-processor using OOP
features in Java. The output of Pass-I (MNT, MDT and file without any macro definitions) should be input
for Pass-IL.
Objectives:
- To Identify and create the data structures required in the design of macro processor.
- To Learn parameter processing in macro
= To implement pass IT of macroprocessor
Problem Statement: Write a program to create pass-I Macro-processor
Outcomes: After completion of this assignment students will be able to:
- Understand the Programming language of Java
- Understand the concept of Pass-I Macro-processor
Software Requirements: Windows OS, JDK1.7
Theory Concepts:
MACRO:
* Macro allows a sequence of source language code to be defined once & then referred to by name
each time itis to be referred.
*| Macro, Assembler
Preprocessor
‘Macro with macro
Definitions and Target program
Macro calls
Program without macros
Macro Preprocessor Macro preprocessor is system software.
It is actually a program, which is a part of the assembler program.
A macro preprocessor accepts an assembly level program containing macro definitions and calls and
translate it into an assembly program which does not contain any macro definition and macro call.
Each time this name occurs is a program the sequence of codes is substituted at that point.
A macro consist of
1. Name of the macro
2. Set of parameters
3. Body of macro
* Macros are typically defined at the start of program, Macro definition consists of
1.MACRO Start
2.MACRO name
3.Sequence of statements(MACRO Body)4.MEND End
‘+ A macro is called by writing the macro name with actual parameter is an assembly program, The
macro call has following syntax .
{]
* Macro processor takes a source program containing macro definition & macro calls and translates
into an assembly language program without any macro definition or calls.
© This program can now be handled over to a conventional assembler to obtain the target language.
MACRO DEINITION:-
'* Macros are typically defined at the start of a program.
+ A macro definition consists of
1. MACRO pseudo code 2. MACRO name 3. Sequence of statement 4. MEND pseudo opcode
terminating macro definition Structure of a macto
Macro instruction definition
MACRO ‘start of definition
INCR macro name
} Sequence to be abbreviated
MEND Pend of definition
«Example
MACRO INCR & ARG
ADD AREG,& ARG
ADD BRA,& ARG
ADD CREG, & ARG
MEND
MACRO CALL:-
Syntax of macro call
{]
MACRO Expansio
‘© During macro expansion each statement forming the body of the macro as picked up one by one
sequentially.
a. Each statement inside macro may have as it is during expansion.
b. The name of a formal parameter which is preceded by the character ‘&’ during macro
expansion an ordinary starting is retained without any modification. Formal parameters are
replaced by actual parameters value.
© When a call is found the call processor sets a pointer the macro definition table pointer to the
corresponding macro definition started in MDT. The initial value of MDT is obtained from MDT
index.Design of macro processor:~
Pass I:
Generate Macro Name Table (MNT)
Generate Macro Definition Table (MDT)
Generate IC i.e. a copy of source code without macro definitions
MNT:
eNO ‘Macro Name MDT index
MDT:
SuNo | MACRO STATEMENT
ALA:
Tradex] Argument
‘Specification of Database
© Pass I data bases
1. The input macro source desk.
2. The output macro source desk copy for use by passes 2.
3. The macro definition table (MDT) used to store the names of defined macros.
4, Macro name table (MDT) used to stare the name of defined macros
5. The Macro definition table counter used to indicate the next available entry in MNT.
6. The macro name table counter counter(MNTC) used to indicate next available entry in MNT.
7. The arguments list array (ALA) used to substitute index markers for dummy arguments
before starting a macro definition.
Pass II:
Replace every occurrence of macro call with macro definition. (Expanded Code)
«There are four basic tasks that any macro instruction process must perform:
1, Recognize macro definition: A macro instruction processor must recognize macro
definition identified by the MACRO and MEND pseudo-ops. This tasks can be complicated
when macro definition appears within macros. When MACROs and MENDs are nested, as
the macro processor must recognize the nesting and correctly match the last or or outerMEND with first MACRO. All intervening text, including nested MACROs and MENDs
defines a single macto instruction
Save the definition: The processor must store the macro instruction definition, which it
will need for expanding macro calls.
3. Recognize calls: The processor must recognize the macro calls that appear as operation
mnemonics. This suggests that macro names be handled as a type of op-code.
4, Expand calls and substitute arguments: The processor must substitute for dummy or
macro definition arguments the corresponding arguments from a macro call; the resulting
symbolic text is then substitute for macro call. This text may contain additional macro
definition or call.
Specification of Database
© Pass 2 database:
1. The copy of the input source deck obtained from Pass- I
2. The output expanded source deck to be used as input to the assembler
3. The Macro Definition Table (MDT), created by pass 1
4. The Macro Name Table (MNT), created by pass 1
5. The Macro Definition Table Counter (MNTC), used to indicate the next line of text to be
used during macro expansion
6. The Argument List Array (ALA), used to substitute macro call arguments for the index
markers in stored macro definition
Eg:- Consider the following Macro definition and the tables constructed in pass I for this macro
MACRO
&LAB INCR — &ARG1,8,ARG2,&ARG3
&LAB
MoT
ADD 1,&ARG1
ADD
2,8ARG2
ADD
3,BARG3
Index Macro MDT Index
Name
T INCR T
Index Label Instruction | operands
‘ADD 1
‘ADD 1.42
T #0
2
3
(4 venaALA
‘Argument Dummy name
&Lab #0
&Argl a
&Arg? 2
&Arg3 B
Steps to follow:-
1.Read the ALP word by word using fgete.
2.1 keyword MACRO is found then
* Store the arguments in ALA in sequence(0" argument for a label),
+ Store all the instructions in MDT using dummy names of the arguments(prepared
in ALA).
+ Store the MDT index in a variable temp.
+ Store name of macro and its MDT index using temp in MNT.
3. Write all the tables onto a file (as these will be required in pass 11)
4.Go to Pass 1
The task of pass II is macro expansion i.e deal with macro calls. For this we use the tables created in pass I
of a macto-processor. Whenever a call to a macro is found for eg:
LOOP INCR Datal,Data2,Data3
(with respect to the macro definition INCR in previous assignment)
Then this call should lead to a macro expansion as follows:-
LOOP: ADD 1, Datal
ADD 2, Data2
ADD 3, Data3
Here the formal parameters are repla
ed by actual parameters.
For this ALA has to be updated with new parameter names.
ALA
‘Argument ‘Actual
Parameters
#0 LOOP
a Datal
@ Data
B Data3
Using these values we expand the macro with the help of MNT and MDT.Steps to follow:-
1.Read the source program.
2.1 an macro name is encounterd it means there is a call to the macro so do the following.
‘+ Search for the macro in the MNT.
‘+ Extract its MDT index and go to that index position in MDT.
+ Update ALA with actual parameters.
3.Read from MDT and replace dummy parameters with actual parameters.
4, Do step 3 till end of macro.
PASS-1 Algorithm
+ Pass] of macro processor makes a line-by-line sean over its input.
+ Set MDTC = | as well as MNTC = 1
+ Read next line from input program,
+ If it is a MACRO pscudo-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-definitions have been processed, so
control is transfered to pass2
PASS-2 Algorithm
+ This algorithm reads one line of input program 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.c. when call is pointer called MDTF to corresponding macro
definitions 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.
“Reading proceeds from the MDT, as each successive line is read, The valves form the argument
list one substituted for dummy arguments indices in the macro definition.
* 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.:
>Conclusion: Thus, we have studied and implemented Pass-I and Pass-II of Macro Processor.