System Software Ch4
System Software Ch4
Syllabus
Introduction, Macro definition and call, Macro expansion, Nested macro calls, Advanced macro
facilities, Design ofa macro pre-processor, Design of amacro assembler, Functions ofa macro
processor, Basic tasks of a macro processor, Design issues macroprocessors, Features, Macro
of
Contents
4.1 Macro Definition and Call. Winter-18, Summer-19, Marks 4
4.2 Macro Expansion Winter-17,19;
Summer-18,19, Marks 4
4.3 Nested Macro Calls Winter-15,17, 18,19, Marks 7
4.4 Advanced Macro Facilities Winter-18,19,
Summer-18. Marks 7
4.5 Macro Processor Algorithm and
Data Structure Summer-17, 19, Marks 7
4.6 Design of Macro PreproOcessor. Summer-17, 18,
Winter-19, Marks 7
4.7 Specification of Database
4.8 Multiple Choice Questions
4.9 Short Questions and Answers
(4- 1)
System Sofware 4 -2 Macro and Macro ProcesSOrs
Macro expansion
Review Questions
1. WriteMacro definition for adding two numbers that uses positional and keyword parameters.
GTU : Winter-18, Marks 3
2. Define Macro-preprocessor. Explain steps of macro preprocessor design.
GTÚ Summer-19, Marks 4
as
Syntax & written
parameter name
Example : &ROLLNO
where ROLLNO is the name of a parameter. In positional parameter
<parameter kind is omitted. The < actual parameter spec is
> a
call on a macro using
>
Example
MACRO
INCR 8:MEM VAL &INCR VAL ®
MOVER ®, &MEM VAL
ADD ®, &INCR VAI
MOVEM ®, &MEM VAL
MEND
INCR VL
REG AREG
MOVEM AREG, A
arguments
Withpositional parameters, the programmer must be careful to specify the
most macro instructions.
order. Positional parameter are quite suitable for
in the proper
parameter the same value in most calls. When the desired value is different from
the has
a macro call. Syntax for
the default value, the desired value can be specified explicitly in
formal parameter specification is as follows
:
Review Questions
1. Explain attributes of
formal parameter and expansion time variable in macro.
4
GTU Winter-17, Marks
2. Explain following terms with suitable example : Positional parameter.
TECHNICAL PUBLICATIONS -
Calls
A3 Nested Macro GTU: Winter-15,17,18,19
• Macro may call another macro in nested macro call. Called macro called as
is
macro whereas macro containing the nested call as the outer macro.
inner
Expansion of nested macros calls follows the last in first out rule. For example
:
MACRO
COMPUTE &FIRST &SECOND
MOVEM BREG, TMP
INCR D &FIRST &SECOND REG- BREG
MOVER BREG, TMP
MEND
program the macro COMPUTE contains a nested call on macro
In the above
INCR_D. The expanded .code for the call
COMPUTE
a call on macro
The second model statement of COMPUTE is recognied to be
macro cal is as
INCR_D after the lexical expansion. The expanded code for a nested
follows.
1. MOVEM BREG. TEMP 1|
An attempt to expand this macro will generate INST1 and will then start the inner
expansion. The inner expansion will do the same thing. It will generate INST1 and
start a third expansion. There is nothing in this macro to stop any of the inne
expansions and go back to complete the outer ones. Such an expansion will vo
quickly overflow the MES, no matter how large it is. It turns out, though, th
such macros, called recursive macros, are very useful. To implemnent such a macr
a mechanism is necessary that will stop the recursion (the self expansion) at sor
point. Such a mechanism is supported by many assemblers and is called conditinv-t
assembly.
Review Questions
1. Give suitable example for nested macro call vith its data structure.
GTU : Winter-17, Marks 7
2. Write a macro definition for adding two numbers 10 times. Use nested macro
call to increment
numbers by 1 every time in 10 iterations. GTU: Winter-18, Marks 4
3. Explain Nested macro call with suitable example. GTU : Summer-19. Marks 3
4. Illustrate expansion of nested macro calls by giving example. :
GTU Winter-19, Marks 4
5. Write definition of semantic expansion. GTU : Winter-19, Marks I
value of the formal parameter. The type, length and size attributes
have the names I, L
and S.
For example
MACRO
CLEAR &A
MOVER AREG, =0
MOVEM AREG, &A
MOVEM AREG, &A +1
MOVEM AREG, BA +2
MEND
When CLEAR B is called, the MOVER
statement puts the value '0' in AREG. The
consecutive bytes with the
Lemaining three MOVEM statement store this value in three
addresses B, B + 1, B + 2.
2) Semantic Expansion of a
For example
MACRO
CLEAR &A, &B
LOL &M
&M SET 0
MOVER AREG,= '0
AGAIN MOVEM AREG, &A + &M
+
Review Questions
TECHNICAL PUBLICATIONS- An up
thrust for knowledge
Sofiware
System 4- 11 Macro and Macro Processors
MEND / END
OF RDBUFF
WRBUFF MACRO
MACROX MACRO
RDBUFF MACRO
:
TECHNICAL PUBLICATIONSo - An up
thrust for knowledge
Sofiware
System 4- 13 Macro and Macro Processors
the macro 1s expanded, arguments from ARGTAB are substituted for the
Ås
corresponding parameters in the macro body.
Algorithm for.a one-pass macro processor.
Start
EXPANDING FALSE -
COPCODE
While END do
begin
CETLINE
PROCESSLINE
end(while}
end macro processor
procedure PROCESSLINE
begin
search NAMTAB for OPCODE
if
found then
XAV
else if OPCODE MACRO Ihen
DEFINE
wiite source line to expandedfile
else
end PROCESSLINE
procedre DEFINE,
begin
er macIO name into NAMTAB
enter
enter macro prototype into DEETAB
LEVEL 1
LEVEL
While 0 do
begin
CGETLINE
if this is not comment line then
a
begin
Substitute positional notation tor parameters
enter line int0 DEFTAB
if OPCODE MACRO then
LEVEL LEVEL1
end ifnot comiment
end while end of definition
Store in NAMTAB pointers to begining and
end (DEFINE}
procedure EXPAND
beqin
RXP ANDING TROE
{prototpe} from DEFTAB
get first line ofmacro definition
up argumnents from macroinvOcation in ARGTABwIite
Set ag a Comment while not
macro invocationto exoanded file
end of macro definition do
TECHNICAL
PUBLICATIONs -An up thrust for knowledge
/
Macro and Macro
System Software 4- 14 ProcesSSors
begin
GETLINE
PROCESS LINE
end {while}
EXPANDING := FALSE
end {EXPAND}
procedre GETLINE
begin
EXPANDING then
if
begin
get next line of macro definition from DEFTAB
substitute arguments from ARGTAB for positional
notation
end {if}
else
read next line from input file
end {GETLINE}
Fig. 4.5.2 shows portions of the contents of these tables during the processing of
the program Fig. 4.5.2 (a) shows the definition of RDBUFF stored in DEFTAB, with
an entry in NAMTAB identifying the beginning and end of the definition.
DEFTAB
NAMTAB
Fig. 4.5.2 (b) shows ARGTAB as it would appear during expansion of the RDBUFF
statement. In thus invocation, the first argument is F1, the second is BUFFER etc.
This scheme makes substitution of macro arguments much more efficient.
ARGTAB
F1
2BUFFER
3 LENGTH
d. This process is very much like matching left and right parentheses when
Scanning an arithmetic expressioni.
Review:Questions
1. Write and explain the algorithm for macro expansion. GTU 1Summer-17, Marks 4
SSTAB.
tplain tise and field
of
following tables of a macro KPDTAB, MDT, EVTAB,
7
GTU Summer-19, Marks
Program
with macro Macro
preprocessor Assembler Target
definitions program
and calls
Program
without
macros
Parameter Default Table (PDT) is used in each macro for constructing the table with
information. Information required for this is the namnes of formal parameters and default
walhues of keyword parameters. This table is accessed by the MNT entry of a macro and
Pair is replaced by another table called APTAB which only contains < value >. For
implementing PNTAB, ordinal numbers are assigned to all parameters of a macro.
PNTAB is parameter name table is used while processing the definition of a macro.
Farameter names are entered in PNTAB in..the same order in which they appear in the
Prototype statement. Th entry.# of a parameter's. entry in PNTAB is now its ordinal
number.
Lne nformation (< formal parameter name >, < value >) in APT has been split
into two tables.
R1 SSNTAB MORE
CLRMEM 2 1 1 25 10 5
MNT
KPDTAB
10 R1 AREG
SSTAB
5 28
MDT
24
25 LCL (E, 1)
26 (E, 1) SET
27 MOVER (P, 3) '0
i*******
28 MOVEM (P, 3), (P. 1) + (E, 1)
29 E,
(E, 1) + 1
1)
SET
30 AIF (E, 1) NE (P, 2)) (S,1)
31 MEND
32
APTAB
AREA
10
AREG
EVTAB
Pass 1
1. Macro definition 2. SYMTAB construction
processing
Pass 2
1. Macro 2. Memory allocation and, LC processing
expansion
3. Processing of literals 4. Intermediate code generation
Pass 3
1. Target code generatiorn
MMacro provide several advantages when writing assembly program.
1. The frequent use of macros can reduce programmer induced errors.
Pass 1
Search others GO TO
Found Type ? PASS:2
Pseudoop Table
MACRO
-
Not pseudo-op
Search Process macro Process
Macro Name Table definition pseudo-ops
Not
Search R (R)
Machine-op Table
Found, macro call
pisadvantages
Combined Pass 1
of the assembler and the macro processor
1. may be too large for a
Review Questions
7. ALA is used to substitute index, markers for dummy arguments before storing a
macro definition.
4. MNT is cteated by
Pass 1.
). MDTP is used to indicate the next line of text to be used during macro expansion.
6. ALSA is used to substitute macro call argument for the index markers in the stored
macro definition.
4.7.3 Pass 1 Flowchart
It tests each input line. If it is a MACRO pseudo-op then the entire macro
definition that follows is saved in the next available locations in the MDT.
Fig. 4.7.1 shows the flowwchart of Pass 1.
TECHNICAL PUBLICATIONS
-
An up thrust for knowledge
4 - 22
Macro and Macro
Processor.
System Software
Pass 1
MDTC =1
MNTC =1
Read next
SOurce card
Write copy of
MACRO No source card
pseudo-op
End No
Yes pseudo-op
Go to
PASS2
Enter macro name
and current value
of MDTC in MNT
Read next
=
Source card
MNTC MNTC+1
Sübstitute index
Prepare argument notation for
list array arguments
=
MDTC MDTC+1
MDTC= MDTC+1
Yes MEND No
pseudo-op
the Macro Name Table (MNT) along with a pointer to the first location of tne
MDT entry of the definition. of the
When END
pseudo-op statement is read, allorder to
macro definitions have been
processed so control transfers to Pass 2 in
process maCro calls.
TECHNICAL PUBLICATIONS - An up
thrust for knowledge
Macro and Macro Processors
Software
4- 23
System
Flowchart
A7.4 Pass 2
tests operation mnemonic of each input line, whether the
Pass 2 algorithmn the is
if call is found in MDTP which
name is entered into MNT. It sets the pointer
pass 2 flowchart.
ctored in MDT. Fig. 4.7.2 shows
macro exparnder
MT index is used for the initial value
of the MDTP. The
a table dummy arguments
prepares the Argument List Array (ALA) consisting of
Pass 2
Yes End No
pseudo-op
MDTP = MDT index
from MNT entry Yes
Supply expanded
sOurce file to
Set up argument assembler
list array
MDTP = MDTP +1
Substitute arguments
from macro call
Review Question
1. Do as directed :
TECHNICAL PUBLICATIONS
An up thrust for knowledge
ystem
Sofiware 4 - 27 Macro and Macro Processors
Q.1
Define macro.
. A
macro is a
unit of specification for program generation through expansion.
a.2 What is meant by macro tme variable ?
.
Macro time variable used to store working values during the macro
expansion
Q.3 Define macro definition
BRe enclosed between a macro header statement and a macro end statement.
t is
Macro definition typically located at the start of a program.