Академический Документы
Профессиональный Документы
Культура Документы
Chapter
3
MACROPROCESSOR
:
:
A 1,DATA Add contents of DATA to register 1
A 2,DATA Add contents of DATA to register 2
A 3,DATA Add contents of DATA to register 3
:
:
A 1,DATA Add contents of DATA to register 1
A 2,DATA Add contents of DATA to register 2
A 3,DATA Add contents of DATA to register 3
:
:
DATA DC F'2'
:
:
MACRo
INC
A 1, DATA
A 2, DATA
A 3, DATA
MEND
INC A 1, DATA
A 2, DATA
A 3, DATA
INC
A 1, DATA
A 2, DATA
A 3, DATA
MACRO
SUB 1 &PAR
L 1, & PAR
A 1, = F'2'
ST 1, &PAR
MEND
MACRO
SUBST &PAR1, &PAR2, &PAR3
SUB1 &PAR1
SUB1 &PAR2
SUB1 &PAR3
2MEND
You can easily notice from this example that the definition of the macro 'SUBST' contains
three separate calls to a previously defined macro 'SUB1'. The definition of the macro SUB1 has
shortened the length of the definition of the macro 'SUBST'. Although this technique makes the
program easier to understand, at the same time, it is considered as an inefficient technique. This
technique uses several macros that result in macro expansions on multiple levels. The following
code describes how to implement a nested macro call:
Macroprocessor 3-5
This is clear from the example that a macro call, SUBST, in the source is expanded in the
expanded source (Level 1) with the help of SUB1, which is further expanded in the expanded
source (Level 2).
MACRO
SUB1 &PAR
L 1, &PAR
A 2, = f’2’
ST 1, &PAR
MEND
MACRO
SUBS &PAR1, &PAR2, &PAR2
SUB1 &PAR1
SUB1 &PAR2
SUB1 &PAR3 Expansion of SUBST Expansion of SUB1
MEND
SUB1 DATA2
L 1, DATA2
SUB1 DATA3 A 2, = f’2’
ST 1, DATA2
L 1, DATA3
A 2, = f’2’
ST 1, DATA3
Macro calls within macros can involve several levels. This means a macro can include within
itself any number of macros, which can further include macros. There is no limit while using
macros in a program. In the example discussed, the macro SUB1 might be called within the definition
of another macro. The conditional macro facilities such as AIF and AGO makes it possible for a
macro to call itself. The concept of conditional macro expansion will be discussed later in this unit.
The use of nested macro calls is beneficial until it causes an infinite loop. Apart from the benefits
3-6 Macroprocessor
provided by the macro calls, there are certain shortcomings with this technique. Therefore, it is
always recommended to define macros separately in a separate file, which makes them easier to
maintain.
:
:
:
A 1,DATA1
A 2, DATA1
A 3, DATA1
:
:
:
A 1,DATA2
A 2,DATA2
A 3,DATA2
:
:
:
A 1,DATA3
A 2,DATA3
A 3,DATA3
DATA1 DC F'5'
DATA2 DC F'10'
DATA3 DC F'15'
Macroprocessor 3-7
In this example, the instruction sequences are very much similar but these sequences are not
identical. It is important to note that the first sequence performs an operation on an operand DATA1.
On the other hand, in the second sequence the operation is being performed on operand DATA2.
The third sequence performs operations on DATA3. They can be considered to perform the same
operation with a variable parameter or argument. This parameter is known as a macro instruction
argument or dummy argument. The program, previously discussed, can be rewritten as follows:
INC &PAR
A 1, &PAR
A 2, &PAR
A 3, &ARG
MEND
:
:
:
INC DATA1 Use DATA1 as operand A 1,DATA1
: A 2,DATA1
: A 3,DATA1
:
These selections are based on the conditions specified in a program. Branches and tests in the
macro instructions permit the use of macros that can be used for assembling the instructions. The
facility for selective assembly of these macros is considered as the most powerful programming
tool for the system software. The use of the conditional macro expansion can be explained with the
help of an example. Consider the following set of instructions:
LOOP 1 A 1,DATA1
A 2,DATA2
A 3,DATA3
:
:
LOOP 2 A 1,DATA3
A 2,DATA2
:
:
DATA1 DC F'5'
DATA2 DC F'10'
DATA3 DC F'15'
In this example, the operands, labels and number of instructions generated are different in
each sequence. Rewriting the set of instructions in a program might look like:
:
:
MACRO
&PAR0 VARY &COUNT, &PAR1, &PAR2, &PAR3,
A 1, &PAR1
AIF (&COUNT EQ 1). FINI Test if & COUNT = 1
A 2, &PAR2
AIF (&COUNT EQ 2). FINI Test if & COUNT = 2
ADD 3, &PAR3
.FINI MEND
: Expanded source
:
LOOP1 VARY 3,DATA1, DATA2, DATA3 LOOP1 A 1,DATA1
A 2,DATA2
: A 3,DATA3
:
LOOP2 VARY 2,DATA3, DATA2 LOOP2 A 1,DATA3
: A 2,DATA2
:
DATA1, DC F’5’
DATA2, DC F’10’
DATA3, DC F’15’
Macroprocessor 3-9
The labels starting with a period (.) such as .FINI are macro labels. These macro labels do not
appear in the output of the macro processor. The statement AIF (&COUNT EQ 1).FINI directs
the macro processor to skip to the statement labelled .FINI, if the parameter corresponding to &
COUNT is one. Otherwise, the macro processor continues with the statement that follows the AIF
pseudo-op.
AIF pseudo-op performs an arithmetic test and since it is a conditional branch pseudo-op, it
branches only if the tested condition is true. Another pseudo-op used in this program is AGO,
which is an unconditional branch pseudo-op and works as a GOTO statement. This is the label in
the macro instruction definition that specifies the sequential processing of instructions from the
location where it appears in the instruction. These statements are indications or directives to the
macro processor that do not appear in the macro expansions.
We can conclude that AIF and AGO pseudo-ops control the sequence of the statements in
macro instructions in the same way as the conditional and unconditional branch instructions direct
the order of program flow in a machine language program.
MACRO
INSTRUCT &ADD Macro name : INSTRUCT
MACRO
&ADD &Z Dummy macro name
De?nition CNOP 0,4 Align boundary
De?nition of
of macro BAL 2,& + 8 Set register 2 to parameter list pointer
macro &ADD
INSRUCT DC A(&Z) Parameter list pointer
L 15,=Y(&ADD) Address of subroutine
BALR 14,15
MEND
MEND
In this code, first the macro INSTRUCT has been defined and then within INSTRUCT, a new
macro &ADD is being defined. Macro definitions within macros are also known as "macro definitions
within macro definitions".
A 2, #2
A 3, #3
MEND
4. The Macro Name Table (MNT), which can be used to store the names of defined macros.
Each MNT entry consists of a character string such as the macro name and a pointer such
as index to the entry in MDT that corresponds to the beginning of the macro definition.
Table 2.2 shows the MNT entry for INCR macro:
3-12 Macroprocessor
Table 3.2: MNT
A 2, #2
A 3, #3
MEND
5. The Macro Definition Table Counter (MDTC) that indicates the next available entry in the
MDT.
6. The Macro Name Table Counter (MNTC) that indicates the next available entry in the
MNT.
7. The Argument List Array (ALA) that can be used to substitute index markers for dummy
arguments prior to store a macro definition. ALA is used during both the passes of the
macro pre-processor. During Pass 1, dummy arguments in the macro definition are replaced
with positional indicators when the macro definition is stored. These positional indicators
are used to refer to the memory address in the macro expansion. It is done in order to
simplify the later argument replacement during macro expansion. The ith dummy argument
on the macro name card is represented in the body of the macro by the index marker symbol
#. The # symbol is a symbol reserved for the use of macro pre-processor.
Table 3.3: ALA
A 2, #2
A 3, #3
MEND
Macroprocessor 3-13
3.6.1.2 Second Pass
Second pass of two-pass algorithm examine each operation mnemonic such that it replaces
macro name with the macro definition. The various data-bases used by second pass are:
1. The copy of the input macro source deck.
2. The output expanded source deck that can be used as an input to the assembler.
3. The MDT that was created by pass 1.
4. The MNT that was created by pass 1.
5. The MDTP for indicating the next line of text that is to be used during macro expansion.
6. The ALA that is used to substitute macro calls arguments for the index markers in the
stored macro definition.
Pass 1
MDTC = 1
MNTC = 1
Is Is END
NO Create a copy of
MACRO pseudo
Pseudo-op source card Opcode is NO
encountered found
YES YES
Read next Input from Go to PASS 2
Source card
MNTC = MNTC + 1
Substitute arguments with
index notation
Prepare ALA
MDTC = MDTC + 1
Is
Read next Input from MEND NO
Source card pseudo
opcode
encountered
YES
YES
YES
MDTP = MDT index
from MNT
Feed expanded source ?le
to assembler processing
Prepare ALA
DTP = MDTP + 1
Is
MEND NO Write expanded
pseudo source card
opcode
encountered
YES
One-pass
macro Is
processor MACRo Write into expanded
Psuedo opcode source card ?le
found ?
Yes,
MDTC – 1 macro de?nition Is
MNTC – 1 Macro END
MDI – ‘OFF’ READ * x
MDLC – 0 name Pseudo opcode
line found ?
READ*
Prepare ALA
Substitute index
notation for arguments
in de?nition
MDTC – MDTC + 1
Yes
MDLC – MDLC + 1
No Yes
MDLC – MDLC – 1
No
x MDLC – 0
?
Figure: 3.4(a)
MACROX for SIC/XE Machine
1 MACROX MACRO {De?nes SIC/XE macros}
2 RDBUFF MACRO &INDEV, &BUFADR, &RECLTH
.
. {SIC/XE version}
.
3 MEND {End of RDBUFF}
4 WRBUFF MACRO &OUTDEV, &BUFADR, &RECLTH
.
. {SIC/XE version}
5 MEND {End of WRBUFF}
.
.
.
6 MEND {End of MACROX}
Figure 3.4(b)
3-20 Macroprocessor
• A program that is to be run on SIC system could invoke MACROS whereas a program to
be run on SIC/XE can invoke MACROX.
• However, defining MACROS or MACROX does not define RDBUFF and WRBUFF.
• 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 expansion
in a recursive way is able to handle recursive macro definition.
• Restriction
– The definition of a macro must appear in the source program before any statements
that invoke that macro.
– This restriction does not create any real inconvenience.
The design considered is for one-pass assembler. The data structures required are:
• 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 positional notation
for efficiency in substituting arguments.
• NAMTAB (Name Table)
– Stores macro names
– Serves as an index to DEFTAB
• Pointers to the beginning and the end of the macro definition (DEFTAB)
• ARGTAB (Argument Table)
– Stores the arguments according to their positions in the argument list.
– As the macro is expanded the arguments from the Argument table are substituted for
the corresponding parameters in the macro body.
– The figure below shows the different data structures described and their relationship.
The above figure shows the portion of the contents of the table during the processing of the
program. In fig 3.4(a) definition of RDBUFF is stored in DEFTAB, with an entry in NAMTAB
having the pointers to the beginning and the end of the definition. The arguments referred by the
instructions are denoted by the their positional notations. For example,
TD = X'?1'
The above instruction is to test the availability of the device whose number is given by the
parameter &INDEV. In the instruction this is replaced by its positional value? 1. Figure 3.4(b)
shows the ARTAB as it would appear during expansion of the RDBUFF statement as given below:
CLOOP RDBUFF F1, BUFFER, LENGTH
Macroprocessor 3-21
NAMTAB DEFTAB
RDBUFF
ARGTAB
1 F1
2 BUFFER
3 LENGTH
(a)
(b)
Figure: 3.5
For the invocation of the macro RDBUFF, the first parameter is F1 (input device code), second
is BUFFER (indicating the address where the characters read are stored), and the third is LENGTH
(which indicates total length of the record to be read). When the ?n notation is encountered in a line
from DEFTAB, a simple indexing operation supplies the proper argument from ARGTAB.
The algorithm of the Macro processor is given below. This has the procedure DEFINE to
make the entry of macro name in the NAMTAB, Macro Prototype in DEFTAB. EXPAND is called
to set up the argument values in ARGTAB and expand a Macro Invocation statement. Procedure
GETLINE is called to get the next line to be processed either from the DEFTAB or from the file
itself.
When a macro definition is encountered it is entered in the DEFTAB. The normal approach is
to continue entering till MEND is encountered. If there is a program having a Macro defined within
another Macro. While defining in the DEFTAB the very first MEND is taken as the end of the
Macro definition. This does not complete the definition as there is another outer Macro which
completes the definition of Macro as a whole. Therefore the DEFINE procedure keeps a counter
variable LEVEL. Every time a Macro directive is encountered this counter is incremented by 1.
The moment the innermost Macro ends indicated by the directive MEND it starts decreasing the
value of the counter variable by one. The last MEND should make the counter value set to zero. So
when LEVEL becomes zero, the MEND corresponds to the original MACRO directive.
Most macro processors allow the definitions of the commonly used instructions to appear in a
standard system library, rather than in the source program. This makes the use of macros convenient;
definitions are retrieved from the library as they are needed during macro processing.
3-22 Macroprocessor
Procedure GETLINE
If EXPANDING then
get the next line to be processed from DEFTAB
Else
Procedure EXPAND
Procedure DEFINE
Set up the argument values in ARGTAB
Make appropriate entries in
Expand a macro invocation statement (like in
DEFTAB and NAMTAB
MAIN procedure)
Iterations of
GETLINE
PROCESSLINE
Figure: 3.6
Algorithms
begin {macro processor}
EXPANDINF : = FALSE
while OPCODE = ‘END’ do
begin
GETLINE
PROCESSLINE
end {While}
end {macro processor}
Procedure PROCESSLINE
begin
sarch MAMTAB for OPCODE
if found then
EXPAND
else if OPCODE = ‘MACRO’ then
DEFINE
else write soruce line to expanded file
end {PRCOESSOR}
Macroprocessor 3-23
Procedure DEFINE
begin
enter macro name into NAMTAB
enter macro prototype into DEFTAB
LEVEL :- 1
While LEVEL > do
begin
GETLINE
if this is not a comment line then
begin
substitute positional notation for parameters
enter line into DEFTAB
if OPCODE = ‘MACRO’ then
LEVEL := LEVEL + 1
else if OPCODE = ‘MEND’ then
LEVEL := LEVEL – 1
end {if not comment}
end {while}
store in NAMTAB Pointers to beginning and end of definition
Procedure EXPAND
begin
EXPANDING := TRUE
get first line of macro definition {prototype} from DEFTAB
set up arguments from macro invocation in ARGTAB
while macro invocation to expanded file as a comment
while not end of macro definition do
begin
GETLINE
PROCESSLINE
end {while}
EXPANDING : = FALSE
end {EXPAND}
Procedure GETLINE
begin
if EXPANDING then
3-24 Macroprocessor
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}
Figure: 3.7
Figure:3.9
The above figure shows a macro definition that uses the concatenation operator as previously
described. The statement SUM A and SUM BETA shows the invocation statements and the
corresponding macro expansion.
3-26 Macroprocessor
3.8.2 Generation of Unique Labels
As discussed it is not possible to use labels for the instructions in the macro definition, since
every expansion of macro would include the label repeatedly which is not allowed by the assembler.
This in turn forces us to use relative addressing in the jump instructions. Instead we can use the
technique of generating unique labels for every macro invocation and expansion. During macro
expansion each $ will be replaced with $XX, where xx is a two-character alphanumeric counter of
the number of macro instructions expansion.
For example,
XX = AA, AB, AC…
This allows 1296 macro expansions in a single program.
The following program shows the macro definition with labels to the instruction.
25 RDBUFF MACRO &INDEV, &BUFADR, &RECLTH
30 CLEAR X
35 CLEAR A
40 CLEAR S
45 +LDT #4096 SET MAXIMUM RECORD LENGTH
50 $LOOP TD =X’&INDEV’ TEST INPUT DEVICE
55 JED $LOOP LOOP UNTIL READY
60 RD =X’&INDEV READ CHARACTER INTI REG A
65 COMPR A, S TEST FOR END OF RECORD
70 JEQ $EXIT EXIT LOOP IF EOR
75 STCH &BUFADR, X STORE CHARACTER IN BUFFER
80 TIXR $LOOP HAS BEEN REACHED
90 $EXIT STX &RECLTH SAVE RECORD LENGTH
MEND
The following figure shows the macro invocation and expansion first time.
RDBUFF F1, BUFFER, LENGTH
30 CLEAR X CLEAR LOOP COUNTER
35 CLEAR A
40 CLEAR S
50 +LDT #4096 SET MAXIMUM RECORD LENGTH
55 $AALOOP TD =X’F1’ TEST INPUT DEVICE
60 JED %AALOOP LOOP UNTIL READY
65 RD =X’F1 READ CHARACTER INTI REG A
70 COMPR A, S TEST FOR END OF RECORD
70 JEQ $AAEXIT EXIT LOOP IF EOR
75 STCH &BUFFER, X STORE CHARACTER IN BUFFER
85 TIXR LOOP HAS BEEN REACHED
90 $AAEXIT STX LENGTH SAVE RECORD LENGTH
If the macro is invoked second time the labels may be expanded as $ABLOOP $ABEXIT.
Macroprocessor 3-27
3.8.3 Conditional Macro Expansion
There are applications of macro processors that are not related to assemblers or assembler
programming.
Conditional assembly depends on parameters provides
MACRO &COND
……..
IF (&COND NE ‘’)
part I
ELSE
part II
ENDIF
………
ENDM
Part I is expanded if condition part is true, otherwise part II is expanded. Compare operators:
NE, EQ, LE, GT.
Macro-Time Variables : Macro-time variables (often called as SET Symbol) can be used
to store working values during the macro expansion. Any symbol that begins with symbol & and
not a macro instruction parameter is considered as macro-time variable. All such variables are
initialized to zero.
25 RDBUFF MACRO &INDEV, &BUFADR, &RECLTH, &FOR. &MAXI TH
26 IF (&FOR NE ‘ ’)
27 &EORCK SET 1
28 ENDIF
30 CLEAR X CLEAR LOOP COUNTER
35 CLEAR A
38 IF (&, EORCK EQ 1)
40 Macro-time LDCH =X’&EOR’ SET EOR COUNTER
42 Variable RMO A,S
43 ENDIF
44 IF (&MAXLTH EQ ‘ ’)
45 +LDT #4096 SET MAX LENGTH = 4096
46 ELSE
47 +LDT #&MAXLTH SET MAXIMUM RECORD LENGTH
48 ENDIF
50 $ LOOP TD =X’SINDEV’ TEST INPUT DEVICE
55 JEQ $ LOOP LOOP UNTIL READY
60 RD = X’ SINDEV’ READ CHARACTER INTI REG A
63 IF (& FORCK EQ 1)
65 COMRR A, S REST FOR END OF RECORD
70 JEQ $ EXIT EXIT LOOP IF EOR
73 ENDIF
75 STCH & BUFADR, X STORE CHARACTER IN BUFFER
80 TIXR T LOOP UNLESS MAXIMUN LENGTH
85 JLT $ LOOP HAS BEEN REACHED
90 $EXIT STX &RECLTH SAVE RECORD LENGTH
95 MEND
Figure: 3.9 (a)
3-28 Macroprocessor
Figure 3.5(a) gives the definition of the macro RDBUFF with the parameters &INDEV,
&BUFADR, &RECLTH, &EOR, &MAXLTH. According to the above program if &EOR has any
value, then &EORCK is set to 1 by using the directive SET, otherwise it retains its default value 0.
Fig 3.9(b) Use of Macro-Time Variable with EOF being NOT NULL
Fig 3.9(c) Use of Macro-Time conditional statement with EOF being NULL
Macroprocessor 3-29
Write into
NO
MACRO name expanded
found source
card ?le
YES END
NO
pseudo
MDTP = MDT index Opcode
from MNT entry
YES
Set up argument list
array Supply expanded
source ?le to
assembler
processing
MDTP = MDTP + 1
Substitute arguments
from macro call
MEND Write
pseudo expanded
opcode source card
YES NO
Macroprocessor 3-41
Q.15. What is the need for a macro?
Ans. By running a macro, users are able to trim down time normally consumed by repetitive tasks.
Some macros, like the ones in MS Excel, may also contain functions. Macros are used to
make a sequence of computing instructions available to the programmer as a single program
statement, making the programming task less tedious and less error-prone. (Thus, they are
called "macros" because a big block of code can be expanded from a small sequence of
characters.) Macros often allow positional or keyword parameters that dictate what the
conditional assembler program generates and have been used to create entire programs or
program suites according to such variables as operating system, platform or other factors.
The term derives from "macro instruction", and such expansions were originally used in
generating assembly language code. A stored macro can then be accessed from a menu list or
from the toolbar and run by simply clicking. You can also assign a hotkey to the macro for
even faster access. Since macros can be called automatically as soon as a digital document is
loaded, they have been employed by malicious individuals for creating macro viruses.
Q.16. What are Macro instruction arguments? Explain.
Ans. Macros provides a facility for specifying arguments or parameters in the macro calls. For all
the parameters passed in macro call, there should be dummy arguments in macro definition.
In macro prototype, these arguments are proceeded by an ampersand (&) sign.
Types of parameters or arguments:
1. Positional arguments : These are the parameters that are matched with dummy arguments
in macro prototype according to their position.
2. Keyword arguments : These are the parameters in which arguments in macro call are
matched with dummy arguments by the name as well as the position.
3. Default arguments : The parameters have default value in macro definition are called
Default parameters .These default parameters get their default value if its name does not
appear in macro call.
Q.17. With the help of an example, distinguish between a function and a macro.
Ans. The function is a program's source code that contains set of instruction units that are entitled
to do a specific job, whereas a macro is an open subroutine that replaces given text when a
macro definition is being called. The functions are mainly used in modular programming
whereas macro are found to be used in non-modular programming. The differences between
function and macros are as follows:-
Function Macro
1. The function is a program or source code 1. The macro is an open subroutine that
that contains set of instruction units that replaces given text when a macro
are entitled to do a specific job. definition being called for further
processing.
2. The function calls are made during run 2. The macro calls are made during
time state of a program. assembly process.
3-42 Macroprocessor
Function Macro
3. In case of function, when they are called, 3. In case of macros, the control is not
the control transfers to the definition of transferred; instead the macro definition
the function and after end of the function, replaces that call of macro in the
it returns back to main program. program.
4. The function requires stack to maintain 4. The macro doesn't require any stock,
call and return of function. since there is no call and returns in
macros.
5. The overhead are move in functions due 5. The overhead in case of macros are
to number of calls and returns. comparatively less as compared to
function.
6. The functions are also known as 6. Te macros are known only as open
procedures, subroutines and module. subroutines.
7. The functions are basically emphasized 7. The macros are not entitled to do so.
on called and returned function.
8. The functions are providing only 8. The macro represents commonly used
modular approach, were the problem can group of statements and used only for
be subdivided. smaller programs.
9. main() 9. main()
{ {
........................ ........................
........................ ........................
........................ ........................
function(); macro();
} }
function() macro()
{ {
........................ ........................
........................ ........................
........................ ........................
Print } ("macro"); print("macro");
}
Macroprocessor 3-43
Q.18. What are subroutine reference or extern pseudo-ops?
Ans. SUBROUTINE REFERENCE (EXTRN PSEUDO-OP)
Assembler symbols are either internal or external means that their value is not known to the
assembler but will be provided by the loader, the action of the loader will be discussed in the
following section.
EXTERN E1, E2, etc.
Defines E1, E2, etc. As external symbols to be used in address constants.
Example CALL BETA becomes:
EXTRN BETA
:
:
:
L 15, ABETA
BALP 14, 15
:
:
:
A BETA DC A(BETA)
Q.19. What do you meant by macro instructions?
Ans. The “macro” is an abbreviation for a sequence of operations. Consider the following program:
Example:-
A 1, DATA Add contents of DATA to register 1
A 2, DATA Add contents of DATA to register 2
A 3, DATA Add contents of DATA to register 3
:
A 1, DATA Add contents of DATA to register 1
A 2, DATA Add contents of DATA to register 2
A 3, DATA Add contents of DATA to register 3
:
DATA DC F'5'
:
In the above program the sequence occurs twice.
A 1, DATA
A 2, DATA
A 3, DATA
3-44 Macroprocessor
A macro facility allows us to attach a name to this sequence and to use this name in its place.
We can invent a macro language that allows us to specify the above as a macro definition and
allows us to the definition later. We have chosen to use a 360-type macro language.
Q.20. What is macro processor?
Ans. A macro processor effectively constitutes a separate language processor with its own language.
It has been formed as follows:
Start of definition................................................................................MACRO
Macro name.........................................................................................[]
Sequence to be abbreviated ................
................
................
End of definition.....................................................................................MEND
Q.21. What is the various macro instruction processor that it perform?
Ans. There are four basic tasks that any macro instruction processor must perform.
1. Recognize macro definitions : A macro instruction processor must recognize macro
definitions identified by the MACRO and MEND pseudo-ops. This task can be
complicated when macro definitions appear within macros. When MACROs and MENDs
are nested, as in the example of the previous section, the macro processor must recognize
the nesting and correctly match the last or outer MEND with the first MACRO. All of the
intervening text, including nested MACROs and MENDs, defines a single macro
instruction.
2. Save the definitions : The processor must store macro instruction definitions, which it
will need for expanding macro calls.
3. Recognize calls : The processor must recognize macros 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 the macro call I his text of course, may contain
additional macro definitions or calls.
Q.22. What are the data bases used in macro processor?
Ans. Specification of data base: Te following data bases are used by the two passes of the macro
processor:
Pass 1 data bases:
1. The input macro source deck.
2. The output macro source deck copy for use by pass2.
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
t MDT.
Macroprocessor 3-45
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.
Pass 2 data bases:
1. The copy of the input macro source deck.
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 pointer (MDTP), 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 the stored macro definition.
7. Stop.
Q.23. What are storage classes? Explain.
Ans. Storage classes PL/I offers the programmer three classes of storage (1) static (2) automatic
and (3) controlled.
Static storage is permanent and is assigned at compile time .Storage available in many
programming language such as FORTRAN.
Automatic storage is allocated only when the procedure or block referencing is being executed.
For example if there is a procedure SUBR with an automatic variable A on the first call
SUBR will be assigned a location for A. When the procedure is exited, A's space will be
released for possible use by other procedure. It is possible that a different location will be
assigned to A for each call to SUBR A is automatic storage and is assigned automatically at
execution time.