0% found this document useful (0 votes)
4 views25 pages

System Software Ch4

Uploaded by

psychoboy6232
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views25 pages

System Software Ch4

Uploaded by

psychoboy6232
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

4 Macro and Macro Processors

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

processOr design options, Two-pass macro procesSors, One-pass macro processors.

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

4.1 Macro Definition and Call GTU Winter-18, Summer-9

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.

Macro expansion

Lexical expansion Semantic expansion

Fig. 4.1.1 Macro


A macro represents a commonly used group of statements
in the source
Programming language. The macro processor replaces each macro instruction with
the corresponding group of source language statements. This is called expanding
the macros.
Macro instructions allow the progranmmer to write a, shorthand version of a
program and leave the mechanical details to be handled by
the macro processor.
Macro expansion is a macro name with a set of formal parameters is replaced by
Some code.
Lexical expansion is replacement of a character string by another character string
during program generation.
Semantic expansion is generation of instructions tailored to the requirements of
specific usage.
Macro definition consists of
i) Macro prototype
ii)One of more model
iii) Macro preprocessor
Macro definition is in between a macro header statement
and a macro ena
statement.
Syntax of macro prototype statement
< macro name >[< formal parameter spec >:..)
where
< macro name > = It is in the mnemnonic field of an assembly statement
< formal parameter spec > is in the following form
< parameter name > [< parameter kind > ]

TECHNICAL PUBL.ICATIONS - An up thrust for knowledge


Software 4-3 Macroand Macro Processors
System

Syntax of the macro call is


macrO name >[<actual parameter spec > ; ]

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

4.2 Macro Expansion GTU Winter-17,19, Summner-18,19|

Macro call leads to macro expansion.


Macro call statement is replaced by a sequence of assembly statement in macro
expansion.
• Two key notions are used in macro expansion
a) Expansion time control flow
b) Lexical substitution
Algorithm for macro exparnsion
1. Initialise the Macro Expansion Counter (MEC)

2. Check the statement which is pointed by MEC is not a MEND statement


a) if the statèmnent is model statement
then
expand the statement and
increment the MEC by 1
else
MEC = new value specified in the statement;
3. Exit from the macro
expansion
Tasks involved in macro expansion
1. Identify the macro calls in the program
2. The values of formal parameters are identified
3. Maintain the values of expansion time variables declared in a macro
4. Expansion time control flow is organized
5. Determining the values of sequencing symbols
6. Expansion of a model statement is performed,

yTECHNICAL PUBLICATIONs An up thrust for knowiodge +


Macro and Macro Processors
System Software 4- 4
statements thhat forrm
statement will be expanded into the
Each macro invocation
macro. Arguments from the macro invocation are substituted
the body of the
parameters in the macro prototype (according to their positions).
the
1. In the definition of macro Parameter.
:

2. In the macro invocation Argument.


:

Macro invocation statement


• Comment lines within the macro body will be deleted.
on the macro invocae
itself has been included as a comment line. The label
in tha
statement has been retained as a label on the first statement generated
way as an
macro expansion. We can use a macro instruction in exactly the same
assembler language mnemonic.
substitution of
Each parameter begins with the character & which facilities the
parameters during macro expansion.
The macro name and parameters define a pattern or prototype for the macro
instruction used by the programmer. Body of the macro definition is defined by
the MACRO directive statements. Macro expansion generate these statements. End
of the macro definition is defined by the MEND assembler directive.
• Macro invocation statement that gives the name of the macro instruction being
invoked and the arguments to be used in expanding the macro.
• Each macro invocation statement has been expanded into the statements that form
the body of the macro, with the arguments from the macro invocation substituted
for the parameters in the macro prototype. Parameters and arguments, both are
associated with one another according to their positions.
• After macro processing, the expanded file can be used as input to the assembler.

4.2.1 Lexical Substitution


Lexical substitution consists of three types of strings
a) Ordinary string
b) Name of a formal parameter which is preceded by the character, '&
c) Name of a preprocessor variable
In lexical expansion, only string type 1 is retained without substitution. Other two
string types are replaced by the values of the formal parameters or preprocesso
variables. Actual parameter string is used as the value of a formal parameter.

4.2.2 Positional Parameters


If the parameters and argumnts were associated with each other according to thet
positions in the macro prototype and the macro inyocation statement, then theses
parameters in macro definitions are called as positional parameters.
4-5 Macro and Macro Processors
System Sofware

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
>

positional parameters is simply


an < ordinary string >.
The value of a positional formal parameter ABC is determined by the rule of
positional association as follows
:

1. In macro prototype statement, find original position of


ABC.
2. Also find the actual parameter specification occupying the same ordinal
position in the list of the actual parameters in the macro call statement.
. Let us consider the following program

Example
MACRO
INCR 8:MEM VAL &INCR VAL &REG
MOVER &REG, &MEM VAL
ADD &REG, &INCR VAI
MOVEM &REG, &MEM VAL
MEND

Formal parameter with values are as follows


:

Formall paramneter Value


MEM VAL
B

INCR VL
REG AREG

If we consider the call


NCR A, B, AREG
as
Lexical expansion of the model statement gives the code below.
MOVER AREG,A
B
ADD 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

TECHNICAL PUBLICATIONS An up thrust for knowledge


4 -6
Systom Softwaro

4.2.3 Keyword Parameters

For keyword parameters,


< parameter name > ordinary string
< parameter kind > string '=
spec > written as
actual parameter
<

name > =< ordinary string


< formal parameter
parameter is determined as followWS :
Value of formal
1. Find the actual parameter
specification which look likes
XYZ = < ordinary string
specification of the string ABC. So formal parameter
2. < ordinary string > is in the
value is XYZ = ABC

Default specifications of parameters


is suitable in such condition that.
Standard assumption value is default value. This
a

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
:

&< parameter name I< rmtar


parameter ind
> default value I
>

Macros with mixed parameter lists


Keyword parameters and positional parameters, both uses macro. In this situation,
a
allpositional parameters must precede all keyword parameters. For example :
=
SUMUP X, Y, A
10,
B=n
Here and X Y are positional parameters and
A and B are keyword parameters

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.

GTU; Summer-18. Marks 2

3. Write a brief note on MS-DOS Linker. Marks 7


GTU Summer-19,
4. Write definition of : 1) Macro expansion 2) Lexical expansion
GTU : Winter-19, Marks 2
5. Explain macro expansion in detail.
GTU : Winter-19, Marks 7

6. Explain positional parameters, keywvord parameters


and default value parameters for macro.
4
GTU: Winter-19, Marks

TECHNICAL PUBLICATIONS -

An up thrust for knowledge


Sofiware 4-7 Macro and Macro Processors
System

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
:

MOVEM BREG, TMP


MOVER BREG, P
ADD BREG, Q
MOVEM BREG, P
MOVER BREG, TMP

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|

MOVER BREG, P2|


COMPUTE PQ 2. INCR_D
ADD BREG, a3
3. MOVER BREG, TMP MOVEM BREG,P4|

Expansion of macro is performed after the lexical


expansion and leads to the
mnodel statement of
generation of marked statement 2, 3 and 4. Then the third
COMPUTE is expanded.
Recursive Macros
a macro
case nested macro expansion is the case where
A very important special
an example but, as its name
expands itself. Macro NOGOOD below is such
implies, not a good one.
NOGOOD MACRO
INST1
NOGOOD
INST2
ENDM

TECHNICAL PUBLICATIONS- An up thrust for knowledge


System Sofiware Macro and Macro
4-8 Processor

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

4.4 Advanced Macro Facilities GTU : Winter-18,19,Summer-J8

Advanced macro facilities support semantic expansion.


Provided facility is
grouped into three types.
1. For alteration of flow of control during
expansion.
2. Expansion time variables.
3. Attributes of parameters.
Alteration of flow of control during expansion provides two features.
a) Expansion time sequencing symbols
b) Statements like AIF, AGO and ANOP is expanded.
Syntax of sequencing symbol is
<
ordinary string >
Sequencing symbol is defined by putting it in the label field of a statement in the
macro body. Used in AIF or AGO statement as an
operand.
Syntax of AIF statement
AIF (<expansion>) <sequencing
symbol>
where < expression > =
Relational expression involving ordinary string etc.
Relational expression is true then only control is transferred to the statement
containing < sequencing symbol > in its label field.

TECHNICAL PUBLICATIONS - An up thrust for knowledge


Sofware 4-9 Macro and Macro Processors
System

An ANOP statement is written as


< sequencing symbol > ANOP

and simply has the effect of defirning the sequencing symbol.


(EV)
Expansion time variables
. These variables are used only during the expansion of macro calls. Exparnsion timne
a
variables are local or global. Local EV is created for use only during particular
macro call. Syntax of local and global EV is as follows
:

LCL < EV specification > ;


EV specification > .]
GBL < EV specification > :
EV specification >.]
<EVspecification > has the syntax & < EV name
>

but < EVname > is an ordinary string.


SET statement is used to manipulate the value of EV.
<EV specification > SET < SET expression >
where
<EVspecification > is in the lable field. SET is in the mnemonic field.

Attributes of formal parameters syntax


spec > it also represents information about the
attribute name >< formal parameter
<

value of the formal parameter. The type, length and size attributes
have the names I, L
and S.

1) Expansion Time Loops


exparnsion
Expansion time loops can be written using expansion time variables and
time control transfer statements AIF and AGO.

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.

TECHNICAL PUBLICATIONS- An up thrust for knowledge


Macro and Macro ProCessore
System Sofiware 4- 10

2) Semantic Expansion of a

It is the generation instructions tailored to the requirements


of
specific usage.
variable and advanced macro facilit.
This is possible by combining the expansion time
(AIF, AGO statement).

For example
MACRO
CLEAR &A, &B
LOL &M
&M SET 0
MOVER AREG,= '0
AGAIN MOVEM AREG, &A + &M
+

&M SET &M 1


AIF (&M NE B), AGAIN
MEND
In the above example, CLEAR macro is an instance of semantic expansion. CLEAR
statement generates the number of MOVEM AREG statement and is determined by the
value of the second parameter of CLEAR.
Following example gives the idea about semantic expansion with attributes.
MACRO
CREATE CONST &A, &B
AIF (T &XEOB) BYTE
&A DW 30
AGO HERE
BYTE ANOP
&A DB 30
HERE MEND
This macro creates a constant 25 with the name given by the second parameter. The
type of the constant matches the type of the first parameter.

Review Questions

1. Explain following terms with suitable example : Expansion time variable.


GTU Summer- 18, Marks. 2
2. Explain with examples - expansion time variables, expansion tine statemnents - AIF and AGO for
macrO programming. Show their usage for expansion time loop by giving example.
GTU: Summer-18, Marks 7
3. Write Macro definition with following and expiain.
i) Macro using expansion time loop i) Macro zvith REPT statement
GTU:Winter-18, Marks 7

4. What are advanced macro programming facilitaties ? Explain with example.


7
GTUWinter-19, Marks

TECHNICAL PUBLICATIONS- An up
thrust for knowledge
Sofiware
System 4- 11 Macro and Macro Processors

4.5 Macro Processor Algorithm and Data Structure


GTU ! Summer-17, 19|
Macro processor uses three main data structure.
1
Definition table (DEF TAB)
2. Name table (NAMTAB)
3. Argument table (ARGTAB)
Definition table stores macro definitions. It contains the macro prototype and the
statemernts that make upthe macro body. The macro names are also entered into
NAMT AB, which serves as an index to DEFT AB.
When macro instruction defined, NAMTAB contains pointers to the beginning and
end of the definition in DEFTAB.
Argumernt table (ARG TAB) is used during the expansion of macro invocations.
When a_ macro invocation statement is recognized the argument are stored in
ARGTAB according of their position in the argument list.
The macro names are entered into NAMTAB, which is serves as an index to
DEFTAB. For each macro instruction defined, NAMTAB contains pointers to the
beginning and end of the definition in DEFTAB.
For designing two pass macro processor, all macro definitions are processed
during the first pass and all macro invocation statements are expanded during the
second pass. This type of two pass macro processor would not allow the body of
one macro instruction to contain definitions of other macros. The reason behind is
that, all macros defined during the first pass before any macro invocation were
expanded.
Following example showws the definition of macros within macro body.
a
1 MACROS MACRo /Define SIG standard version macros
2 RDBUFF MACRO

MEND / END
OF RDBUFF
WRBUFF MACRO

MEND I/ End of WRBUFF


MEND 1/ End of macrOs
Fig. 4.5.1 (a)

TECHNICAL PUBLICATIONS-An up thrust for knowledge


System Software 4- 12 Macro and Mecro
Processors

MACROX MACRO
RDBUFF MACRO
:

MEND //END of RDBUFF


4 WRBUFF MACRO

5 MEND / End of WRBUFF


6 MEND / End of MACROX
Fig. 4.5.1 (b)
The body of first macro (MACROS) contains statements that define RDBUFF.
WRBUFF and other macro instructions for a SIC system.
Second macro instruction
body (MACROX) defines these same macros for a SIC\XE system. The same
program could run on either a standard SIC machine or a
SIC\XE machine.
Invocation of MACROS or MACROX is only changed for use.
Defining MACROS
or MACROX does not define RDBUFF
and other macro instructions. These
definitions are processed only when an invocation of MACROS or MACROX is
expanded.
One-pass macro processor
• A one- pass macro processor that alternate
between macro definition and macro
a
expansion in recursive macro definition.
Restriction
1. The definition of a macro
must appear in the. Source program before any
statements that invoke that macro.
2.
This restriction does not create any'real inconvenience.
Data structures for one-pass macro processor
1. DEFTAB (definition table)
Stores the macro definition including macro prototype and macro body.
Comment lines are omitted.
References to the macro instruction parameters are
converted to a positionall
notation for efficiency in substituting arguments.
2. NAMTAB
Stores macrO names.
Serves as an index to DEFTAB.
Pointers to the beginning and the end of the macro definition (DEFTAB).
3. ARGTAB
Stores the arguments of macro invocation according to their positions
in the
argument list.

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

RDBUFF &INDEV, &BUFADR, &RECLTH


CLEAR X
CLEAR A
RDBUFF
+LDT
TD # 4096
JEQ =X'?11
RD *3
COMPR #?1
JEQ A,S
STCH *+11
TIXR ?2,X
JLT
STX *-19
MEND ?3

Fia, 4.5.2 (a) NAMTAB and DEFTAB


entries for defining RDBUFF macro
TECHNICAL PUBLICATIONS-
An up thrust for knowledge
Software 4- 15 Macro and Macro Processors
System

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

(b) ARGTAB entries for invocation of RDBUFF


Fig. 4.5.2
a) DEFINE procedure is, called at beginning of a macro definition and make
appropriate entries in DEFTAB and NAMTAB.
b) EXPAND is called to step the argument values in ARGTAB and expand a macro
invocation statement.
c) GETLINE procedure called to get the next line for process.

Handling Nested Macro Definition


• In DEFINE procedure
1. When a macro definition is being entered into .DEFTAB, the normal approach is to
continue until an MEND directive is reached.
2. This would not work for nested macro definition because the first MEND
encountered in the inner macro will terminate the whole macro definition process.
macro
3. To solve this problemn, a counter LEVEL is used to keep, track of the level of
definitions.
a. Increase LEVEL byeach time a MACRO directive is read.
1

b.. Decrease LEVEL by 1 each time a MEND directive is read.


C. A MEND terminates the.whole macro definition
process when LEVEL reaches
0.

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

TECHNICAL PUBLICATIONS- An up thrust for knowledge


System Sofhware 4- 16 Macro and Macro
ProcossOra

4.6 Design of Macro Preprocessor


GTU: Summer-17, 18, Winter-19
• Fig, 4.6.1 shows the schematic of a macro preprocessor.

Program
with macro Macro
preprocessor Assembler Target
definitions program
and calls

Program
without
macros

Flg. 4.6.1 Macro preprocessor


Input to the macro preprocessor is an assembly program with definitions and call
and translate it into an assenmbly program which does not contain any macro
definitions or calls.

4.6.1 Design Overview


Design process involves following task in macro expansion.
1. Macro calls in the program is recognised.

2. The value of formal parameters is calculated.


3. Maintain the value of expansion time variables declared in a macro.
4. Expansion time control flow is organized properly.
5. Determine the values of sequencing symbols.
6. Perform expansion of a model statement.

Design specification for each task is as follows :


1. Task is performed by identifying necessary
information.
2. Design a suitable data structure to record the information.
3. Determine the processing necessary to obtain the information.
4. Determine the processing necessary to perform the task.
Macro Name Table (MNT) : MNT is used to hold the names of macros defined n a
program. When macro definition is processed, a macro name is entered in the macro
name table. At the time of processing source program
the preprocessor copares
string found in its mnemonic field with the macro names in MNT.
e

TECHNICAL PUBLICATIONS- An up thrust for knowledge


Sofiware 4- 17 Macro and Macro Processors
System

statement expansion is performed in following way :


Model

1. Model statement contains the MDT entry, which points by MEC.


Value of formal parameter is available in APT and EV in EVT.
a Model statement
define a sequencing symbol and identified from SST.

Values of formal parameters


Actual Paraimeter Table (APT) is designed to hold the values of formal pararmeters
during the
expansion of a macro call. The table contains the following entry.
(< formal parameter name >, < value >)

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

would contain pairs of the form,


(<formal parameter name>, < default value >)
Maintain expansion time variables
.

Maintain expansion time variable is maintained by expansion time variables table


(EVT). Format is as below.

(<EV name >, < value >)


The value field of a. pair is accessed when. a preprocessor statement or a model
statement under expansion refers to an EV.

4.6.2 Data Structures


Data structure discussed in the above section are used for designing the macro
preprocessor. Macro expansion can be made more efficiernt by storing an
intermediate code for a statement. The tables APT, PDT and EVT are used for
searching the key pair.
• The APT
table containing
(< formal parameter namne >, < value >)

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.

TECHNICAL PUBLICATIONS- An up thrust for kriowledge


Macro and Macro PrOcOssore
4- 18
System Software
names used while processing macro
parameter
1) PNTAB It contains formal
definition.
- formal parameter values used for macro expansion.
2) APTAB It contains
for all macros defined in a'program. It contains three pointers.
MNT Ias entries
1) MDTP : Points to MDT
KPDTAB
2) KPDTP points to
3) SSTP points to SSNTAB
In short
1). PNTAB and KPDTAB are constructed by processing
the prototype statement.
to EVNTAB and SSNTAB as EV declarations and Ss
2) Entries are added
definitions are encountered.
the model statement and
3) MDT entries are constructed wwhile processing
preprocessor statement in the macro body.
4) When the definition of sequencing symbol is
a encountered, an entry is added
to SSTAB.
a macro call.,
5) APTAB is cnstructed while processing,
a macro.
6) EVTAB is constructed at the start of expnsion of
For example
MACRO
CLRMEM &P, &Q, &R1 AREG
LLCC &A
0
&A SET
MOVER &R1, 0

MORE MOVEM &R1, &P +&A


SET &A +1
&A
AIF &A+1
MEND (&A NE 0), MORE

Data structure for statement


CLRMEM AREA 10
PNTAB
P EVTAB A

R1 SSNTAB MORE

name # PP 3 KP 3 EV MDTP KPDTP SSTP

CLRMEM 2 1 1 25 10 5

MNT

TECHNICAL PUBLICATIONS - An up thrust for knowledge


Sofiware
System 4- 19
Macro and MacroProcessors

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

4.6.3 Design of Macro Assembler


To design the pass structure of a macro assembler, following process leads the pass
structure :

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.

TECHNICAL PUBLICATIONs An up thrust for knowledge


- Macro and Macro Processors
4
20
System Software

a macro is limited to that mnacro.


k
Ihe scope of symbols used in
are well suited for creating sinple code tables.
J. Macros
IMacro processor within an Assembler an assembler,
can added as a preprocessor to making a
The macro processor
be
text before Pass 1
of an assembler. The macro
Complete pass over the input the assembler.
Pass of
1
processor can also be implemented within
macro processor within Pass 1 eliminates the
The implementation
of the integration of macro prOcessor and
of intermediate files. It also improves the
For example, Macro Narme Table (MNT)
assembler by combining similar functions.
can be combined with the assembler's op-code table.
macro processor combined with assembler pass
Fig. 4.6.2 shows the flowchart of
1.

Pass 1

Read End pseudo-op

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

Process Set up marco


machine stack frame,e
instruction

Fig. 4.6.2 Macro


assembler
Advantages of incorporating the macro processes into pass 1
1. Many functions do not have to be implemented twice.
2. Less overhead during processing.
3. More flexibility is available
t the programmer.
TECHNICAL PUBLICATIONS-An up thrust for knowledge
Sofiware 4 - 21 Macro and Macro Processors
System

pisadvantages
Combined Pass 1
of the assembler and the macro processor
1. may be too large for a

progran to fit into COre of some machines.


2. Complexity of such program may be overwhelming.

Review Questions

1Explain in brief the design of a macro assembler.


GTUSummer-17, Marks.7
2. Explain use and field of
following tables of a macro KPDTAB, MDT, EVTAB, SSTAB.
)
GTUSummer-18, Marks 7
3. Draw figure of macro preprocessor. GTU Winter-19, Marks 3

4:7 Specification of Database


4.7.1 Pass 1 Database
1. Input the macro source deck.
2. Output macro source deck copy for use by Pass 2.

3. MDI is used to store the body of the mnacro definitions.

4. MNT is used to store the names of defined macros.


5. MDTC is used to indicate the next available entry in the MDT.
6. MNTC is used to indicate the next available entry in the MNT.

7. ALA is used to substitute index, markers for dummy arguments before storing a
macro definition.

4.7.2 Pass 2 Database


1. the input macro source deck.
The copy of
2. Output expanded source deck to be used as input to the assembler.

3. MDT is created by Pass 1.

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

Read next Yes


sOurce card

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

Enter line into


Enter macro name MDT
card into MDT

=
MDTC MDTC+1
MDTC= MDTC+1

Yes MEND No
pseudo-op

Fig. 4.7.1 Pass 1 processing macro definitions


into
line then name is entered
If the first line of the definition is the macro name

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

Read next source


card

Search MNT for matchl


with operation code

Macro No Write into expanded


name found source card file
?

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

Get line from


MDT

Substitute arguments
from macro call

Yes MEND No Write expanded


pseudo-op sOurce card
?

Fig. 4.7.2 Pass 2 processing macro calls and expansion


TECHNICAL PUBLICATIONS- An up thrust for knowledge
Macro and Macro Proces90rs
System Software 4- 24

Arguments not represented


indices and corresponding arguments to the call.
are ignored. Reading ofin a
call are considered blank ánd superfluous arguments the
MDT and each line is read. The values
statement proceeds from the from the
argument list are substituted for dummy argument indices in the macro definition.

Review Question

1. Do as directed :

i) A macro is a unit of specification for through expansion. (Fill in the blank)


(Program generation)
i) Macro definition is enclosed between a statement and a statement.
(Fill in the blank) (macro header, macro end)
iii) A is desigmed to hold the nanmes of all macro defined in a program. (Fill in the
blank) (table called macro name table)
iv) An counter is maintained to count the number of nested macro calls. (Fill in the
blank) (expansion nesting)
o) A lexical expansion is typically employed to replaced occurrence of formal parameters by
corresponding actual parameters. (State True/False)
vi) Default specification of parameters is useful in situtations where a parameter
has the different
value in most calls. (State True/False) (False)
vii) Maco definition table is maintained to hold value of sequencing symbols. (State
True/False)
(True)

4.8- Multiple Choice Questions


Q.1, The flow of control during macro expansion is implemented
using a
a
Macro exparnsion counter. [b MEND statement
c Positional parameters d
Conditional expansion
Q.2 Expansion of nested macro calls follows the rule.
a First in first out
c
b Last in first out
Last in last out d
First in last out
Q.3 A table called is designed to hold the values of formal parameters during
the expansion of a macro call.
a
Expansion time variable table
name
b Macro definition table
C Macro table Actual parameter table
d

TECHNICAL PUBLICATIONS
An up thrust for knowledge
ystem
Sofiware 4 - 27 Macro and Macro Processors

4.9 Short Questions and Answers

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.

Q.4 Define macro expansion.


Ans, : A macro call leads to macro expansion. During macro expansion, the macro call
statement is replaced by a sequence of assembly statement.
Q.5 List the statements present in a macro definition.
Ans. :
Statement in måcro definition are RDBUFF, WRBUFF, MACRO and MEND
Q.6 parameter ?
What is the positional
Ans. : With positional parameters, the programmer must be careful to specify the
argument in the proper order. If an argument is to be omitted, the macro invocatiorn
statement must contain a null argument to maintain the correct argument positions.
Q.7 Define subroutine.
Ans. A subroutine is section of the program that is written once and can be used
:

many times by simply calling it from any point in the program

TECHNICAL PUBLICATIONS An up thrust for knowledge

You might also like