1. G. H. Patel College of
Engineering & Technology
Subject : System Programming (2150708)
Topic : Macro Processor
Batch : 1D16
Prepared by:
Khyati Valera (160110116059)
Rutvi Vasani (160110116060)
Bhavik Vashi (160110116061)
Submitted to: Prof. Vinita Shah
2. What is macro?
▶ A macro is a unit of specification for program generation through
expansion.
▶ A macro consists of a name , a set of formal parameters and
body of code.
▶ The use of a macro name with a set of actual parameters is
replaced by some code generated from its body. This is called
macro expansion.
3. MACRO : Example
MACRO -------- Start of definition
INCR -------- Macro name
A 1,DATA
A 2,DATA ------Sequence of instructions to be
A 3,DATA abbreviated
MEND -------- End of definition
4. Basic Macro Processor Functions
A program with
macro definition &
invocation
Macro
Processor
Program without
macro definition
Expanded
Program
Assembler
Object Program
5. NESTED MACRO CALLS
▶ A model statement in a macro may constitute a call on another
macro. Such calls are known as nested macro calls.
▶ Macro containing the nested call is the outer macro and
Macro called is inner macro.
▶ They follow LIFO rule.
▶ Thus, in structure of nested macro calls, expansion of latest
macro call (i.e. inner macro) is completed first.
7. Source code
MACRO
ADD 1, &arg
L 1, &arg
A 1, = F ‘10’
ST 1, &arg
MEND
MACRO ADDS &arg1, &arg2, &arg3
ADD1 &arg1
ADD1 &arg2
ADD1 &arg3
MEND
ADDS data1, data2, data3
data 1 DC F‘5’
data 2 DC F‘6’
data 3 DC F‘7’
END
Expanded Code Level 1
Expansion of AADS
ADD1 data 1
ADD1 data 2
ADD1 data 3
data DC F ‘5’
data DC F ‘6’
data DC F ‘7’
END
8. Expanded Code Level 2
Expansion ofADD1
L 1, data 1
A 1, = F ’10’
ST 1, data 1
L 1, data 2
A 1, = F ’10’
ST 1, data 2
L 1, data 3
A 1, = F ’10’
ST 1, data 3
data1 DC F‘5’
data2 DC F‘6’
data3 DC F‘7’
END
Expanded Code Level 1
Expansion of AADS
ADD1 data 1
ADD1 data 2
ADD1 data 3
data DC F ‘5’
data DC F ‘6’
data DC F ‘7’
END
9. ADVANCED MACRO FACILITIES
▶ Advanced macro facilities are aimed to supporting semantic expansion.
▶ Used for:
▶ performing conditional expansion of model statements and
in writing expansion time loops.
▶ These facilities can be grouped into following.
▶ 1. Facilities for alteration of flow of control during expansion.
▶ 2. Expansion time variables.
▶ 3. Attributes of parameters.
10. AIF STATEMENT
▶ An AIF statement has the syntax
AIF (<expression>) <sequencing symbol>
▶ Where <expression> is a relational expression involving ordinary
strings, formal parameters and their attributes and expansion
time variables.
▶ If the relational expression evaluates to true, expansion time
control is transferred to the statement containing <sequencing
symbol> in its label field.
11. AIF STATEMENT : Example
MACRO
&N MOVE &T,&F
AIF (T'&T NE T'&F).END Statement 1
AIF (T'&T NE 'F').END Statement 2
&N ST 2,SAVEAREA Statement 3
L 2,&F
ST 2,&T
L 2,SAVEAREA
END MEND Statement 4
12. AGO STATEMENT
▶ An AGO statement has the syntax
AGO <sequencing symbol>
▶ Unconditionally transfers expansion time control to the
statement containing <sequencing symbol> in its label field.
13. AGO STATEMENT : Example
MACRO
&NAME MOVE &T,&F
AIF (T'&T EQ 'F').FIRST Statement
1
AGO .END
Statement 2
. FIRST AIF (T'&T NE T'&F).END Statement
3
&NAME ST 2,SAVEAREA
L 2,&F
ST 2,&T
L 2,SAVEAREA
.END MEND Statement
4
14. ANOP STATEMENT
▶ An ANOP statement is written as
<sequencing symbol> ANOP
▶ And simply has the effect of defining the sequencing symbol.
16. Algorithm : Pass 1
▶ 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-definations
have been processed, so control is transferred to pass2
17.
18. Algorithm : Pass 2
▶ 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.e. when call is pointer called MDTF to corresponding
macro definition 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 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