Macro Macro Processor PDF
Macro Macro Processor PDF
Nirmala Shinde
Content
• Introduction
• Features of a macro facility
• Implementation : Two pass macro processor
Introduction
• A macro instruction is a notational convenience for the programmer
• It allows the programmer to write shorthand version of a program (module
programming)
• The macro processor replaces each macro instruction with the
corresponding group of source language statements(expanding).
• Normally, it performs no analysis of the text it handles.
• It doesn’t concern the meaning of the involved statements during macro
expansion.
• The design of a macro processor generally is machine independent!
Macro Example
macro
Basic Functions of Macro Processor
• Macro is a Single Line abbreviation for set of instructions.
• Two new assembler directives are used in macro definition
• MACRO : identify the beginning of a macro definition
• MEND : identify the end of a macro definition
Example
Macro definition – Once the macro has Macro Expansion – Replacement of macro
been defined, the use of the macro name call by corresponding sequence of
as an operation mnemonic is an assembly instructions is called as macro expansion.
called as macro call.
• Source Program • Expanded source
Features of macro facility
• Macro instruction arguments
• Conditional macro expansion
• Macro calls within macros
• Macro instructions defining macros
Macro Instruction Arguments
• 1st sequence with DATA1 & 2nd with DATA2.
• To perform same operation with a variable
parameter/argument.
• Parameter is called as macro instruction
argument or dummy argument.
• They are denoted by leading ampersand (&)
Cont…
Source Expanded Source
Example: more than one arguments
• The operands in the common
sequence are different.
• As well as labels are on the 1st cards
of the sequences.
• Macro can be written as
Cont…
Cont…
• Specifying arguments to a macro call
• Positional argument
• Arguments are matched with dummy arguments according to the order in which they
appear.
• E.g. In a macro call “INCR A,B,C” replaces the 1st (A), 2nd (B), 3rd (C) dummy argument.
• Keyword argument
• Allows dummy arguments by name as well as by position.
• E.g. we may write “INCR &ARG1=A , &ARG2=B, &ARG3=C”
OR
“INCR &ARG1=A, &ARG2=&ARG3=C”
Conditional Assembly
• Conditional assembly, in which the expansion of a macro can lead to a number of
distinct code sequences.
• Conditional assembly permits the testing of attributes such as data format,
data value, or field length, and to use the results of such testing to generate
source code that is specific to the case in question.
• Pass II
• The macro calls are identified and the arguments are placed in the
appropriate place and the macro calls are replaced by macro definitions.
Pass I Specification of Data Bases
• Input – macro source program
• Output – macro source program used by pass II.
• Macro definition table (MDT) – store the body of macro definition
• Macro definition table counter (MDTC) – to mark next available entry
MDT.
• Macro name table (MNT) – used to store names of macros.
• Macro name table counter (MNTC) – used to indicate the next
available entry in MNT.
• Argument list array (ALA) – used to substitute index markers for
dummy arguments before storing a macro definition.
Pass II Specification of Databases
• The copy of source program
• Output expanded program from pass II
• MDT created by pass I
• MNT created by pass I
• Macro definition table pointer (MDTP) - indicate the next line of text
to be used during macro-expansion.
• ALA created by pass I.
Specification of database format
• Macro Definition Table
• Macro Name Table
• Argument List Array
Example: more than one arguments
• The operands in the common
sequence are different.
• As well as labels are on the 1st cards
of the sequences.
• Macro can be written as
MDT
• MDT is a table of text lines.
• Every line of each macro definition
except the MACRO line, is stored in
the MDT (MACRO line is useless
during macro-expansion)
• MEND is kept to indicate the end of
the defn.
• The macro-name line is retained to
facilitate keyword argument
replacement.
MNT
• It serves a fn similar to that
of assembler’s MOT & POT
• Each MNT entry consists of
• A character string (the macro
name)
• A pointer (index) to the entry
in MDT that corresponds to
the beginning of the macro-
definition (MDT index).
ALA
• ALA is used during both Pass1 & Pas2 but for some what reverse functions.
• During Pass 1, in order to simplify later argument replacement during macro
expansion, dummy arguments are replaced with positional indicators when
defn is stored.
• The ith dummy argument on the macro-name is represented in the body by #i.
Ex. # 1, # 2, # 3 etc.
• These symbols are used in conjunction with the argument list prepared before
expansion of a macro-call.
• Symbolic dummy argument are retained on macro-name card to enable the
macro processor to handle argument replacement by name rather by
position.
During Pass I
During Pass II
• During Pass II it is necessary to
substitute macro call arguments for
the index markers stored in the
macro definition.
• Thus upon encountering the call
LOOP INCR DATA1, DATA2, DATA3
• The macro call expander would
prepare an argument list array:
• The list would be used only while
expanding this particular call.
Pass 1
Pass 1 – processing macro definitions
MDTC<-1
MNTC<-1
Read next
source card
MACRO No
Write copy of
pseudo-
source card
op?
Yes
END
pseudo- No
Read next
op?
source card
Yes
Go to Pass 2
Enter macro name and
Read next
current value of MDTC in
source card
MNT entry number MNTC
Substitute
MNTC <- MNTC + 1 index notation
for arguments
MACRO No
Write into
name
expanded source
found?
card file
Yes
END No
MDTP <- MDT index from MNT pseudo-op?
entry
Yes
16 ST 4, DATA4
17 FOUR DC F’4’
18 FIVE DC F’5’
19 TEMP DS ‘1’F’
20 END
Macro Functions (or Subroutines)
Definition Macros are single-line abbreviations of a Functions are blocks of code that are to
small sequence of instructions. be executed repeatedly by the program
Lines of Code Macros are used when number of Functions can be used for any length of
repeating instructions is very small (3 to code that is to be executed repeatedly.
5 instructions)
Type Checking No type checking for macro arguments Function argument type checking is
performed, with prototype & definition
Time of processing Macros are processed at compilation time Functions are processed during execution
time
Processing the call Macro calls are replaced by corresponding When a function is called, its corresponding
sequence of instructions; these instructions are instructions are actually executed.
not actually executed.
Housekeeping No housekeeping operations (pushing and The return address is pushed onto stack, when a
operations popping on the stack) are required. function is called and is popped back when the
function returns.
Need of a Macro calls are not recognized by the Functions (or Subroutines) are executed by the
Preprocessor assembler. So, a separate Macro Processor is Assembler itself (as Procedures)
needed to expand them.
Return value Macros cannot return a value Functions can return a value
Size of the program Macro calls are expanded inline. So, they Functions do not increase the size of the program
increase the size of the program
Speed of execution Since there are no housekeeping operations Housekeeping operations make programs using
involved, programs using macros execute functions execute at lesser speed.
slightly faster than the ones using functions
Reference
• http://www.edwardbosworth.com/MY3121_LectureSlides_HTML/Ma
crosAndStacks_Part2.htm
• http://www-
01.ibm.com/support/knowledgecenter/SSLTBW_1.13.0/com.ibm.zos.
r13.asma400/ago.htm%23ago
• ftp://ftp.software.ibm.com/software/websphere/awdtools/hlasm/s8
167b.pdf
• http://www.edwardbosworth.com/MY3121_LectureSlides_HTML/Ma
crosAndStacks_Part2.htm