Lab Manual –Systems Programming & Operating Systems Lab Dept.
of Computer Engineering
ASSIGNMENT NO.03
TITLE: IMPLEMENTATION OF PASS – I OF TWO PASS
MACRO-PROCESSOR
PROBLEM STATEMENT: Design suitable data structures and implement pass-I of a two-
pass macro-processor using OOP features in Java
OBJECTIVES:
• To understand macro facility, features and its use in assembly language programming.
• To study how the macro definition is processed and how macro call results in the expansion
of code.
SOFTWARE & HARDWARE REQUIREMENTS:
1. 64-bit Open source Linux or its derivative
2. Eclipse
3. JDK
THEORY:
Macro instructions are single line abbreviations for group of instructions. Using Macro,
programmer can define a single instruction to represent block of code. To relieve the
programmer of the need to repeat identical parts of their program operating systems provide
a macro processing facility. A macro is a unit of specification for program generation through
expansion.
Macro Definition
Macro definition typically appears at the start of a program. Each macro definition is enclosed
between a macro header statement and a macro end statement, having mnemonic opcodes
MACRO and MEND. Statements included in the macro definition can use formal parameters
; the ‘&’ is prefixed to the name of a formal parameter to differentiate a formal parameter’s
name from symbolic name.
A macro prototype statement declares the name of the macro and names and kinds of formal
parameters.
<macro name> [<formal parameter specification> [,…]]
International Institute of Information Technology, Hinjawadi, Pune. Page 1
Lab Manual –Systems Programming & Operating Systems Lab Dept. of Computer Engineering
Macro Expansion
The macro processor substitutes the definition for all occurrences of abbreviations (macro call)
in the program. Replacement of macro call by corresponding sequence of instructions is called
as macro expansion. Macro expansion can be performed by using two kinds of language
processors.
• Macro Assembler
• Macro Preprocessor
A macro assembler performs expansion of each macro call in a program into sequence of
assembly statements and also assembles the resulting program.
A macro preprocessor merely performs macro expansion of macro calls in a program.
It produces assembly program in which a macro call has been replaced by statements that
resulted from its expansion but statements that were not macro calls have been retained in
their original form. This program can be assembled using assembler.
Design of a Macro Preprocessor
The macro preprocessor accepts an assembly program containing definitions and calls and
translates it into an assembly program which does not contain any macro definition or call.
The program form output by the macro preprocessor would be handed over to an assembler
to obtain the target program.
This way, a macro facility is made available independent of an assembler, which makes it both
simpler and less expensive to develop.
Design Procedure:-
Tasks involved in macro expansion
• Identify macro calls in the program.
• Determine the values of formal parameters.
• Maintain the values of expansion time variables declared in a macro.
• Organize expansion time control flow.
International Institute of Information Technology, Hinjawadi, Pune. Page 2
Lab Manual –Systems Programming & Operating Systems Lab Dept. of Computer Engineering
• Finding the statement that defines a specific sequencing symbol.
• Perform expansion of a model statement.
Design of Two – Pass Macro Processor
The Two – Pass Macro Processor will have two systematic scans or passes, over the input text,
searching first for macro definitions and then for macro calls.
Just as assembler cannot process a reference to a symbol before its definition, so the macro
processor cannot process a reference to a symbol before its definition, so the macro cannot
expand a macro call before having found and saved macro definition. Thus we need two
passes over the input text, one to handle definitions and one to handle calls.
Design of Two – Pass 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.
Pass II:
• Replace every occurrence of macro call with macro definition.
Macro Processor Pass – I Data Structures
1. The input file (Source Program)
2. The output file (To be used by Pass – II)
3. The Macro Definition Table (MDT), used to store the body of the macro definitions.
4. The Macro Name Table (MNT), used to store the names of defined macros
5. The Macro Definition Table Counter (MDTC), used to indicate the next available entry in
the MDT
6. The Macro Name Table Counter (MNTC), used to indicate the next available entry in the
MNT
7. The Argument List Array (ALA), used to substitute index markers for dummy arguments
before storing a macro definition.
Macro Processor Pass – I (Macro Definition) Algorithm
The algorithm for Pass – I tests each input line. If it is MACRO mnemonic, the entire macro
definition that follows is saved in the next available locations of Macro Definition Table (MDT).
The first line of the definition is the macro name line. The name is entered into the Macro Name
Table (MNT), along with the pointer to the first location of the MDT entry of the definition.
When END mnemonic is encountered, all of the macro definitions have been processed so the
control transfers to Pass – II in order to process macro call.
International Institute of Information Technology, Hinjawadi, Pune. Page 3
Lab Manual –Systems Programming & Operating Systems Lab Dept. of Computer Engineering
Example (Input to Pass-I)
MACRO
FIRST
ADD AREG, BREG
MEND
MACRO
SECOND &ARG1,&ARG2
ADD AREG,&ARG1
SUB BREG,&ARG2
MEND
MACRO
THIRD &ARG1=DATA3,&ARG2=DATA1
ADD AREG,&ARG1
ADD BREG,&AGR2
SUB BREG,&ARG1
MEND
START
:
:
FIRST
:
SECOND DATA1,DATA2
:
International Institute of Information Technology, Hinjawadi, Pune. Page 4
Lab Manual –Systems Programming & Operating Systems Lab Dept. of Computer Engineering
:
THIRD DATA1,DATA3
:
DATA1 DS 3
DATA2 DS 2
DATA3 DC ‘3’
END
PASS I Output
CONCLUSION:
FAQs
1. Define the term macro.
2. Distinguish between macro and a subroutine
3. Define and Distinguish between parameters that can be used in macros.
4. State various tables used in processing the macro.
5. Explain the role of stack in nested macros.
International Institute of Information Technology, Hinjawadi, Pune. Page 5