0% found this document useful (0 votes)
10 views64 pages

Unit - 4 Macros and Macro Processors

Uploaded by

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

Unit - 4 Macros and Macro Processors

Uploaded by

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

Unit – 4

Macros and
Macro Processors
Introduction - Macro

 Facility for extending a programming language.


 Macro instructions called macro are single-line abbreviations for
groups of instructions.

 For every occurrence of this one-line macro instruction within a


program, the instruction must be replaced by the entire block.

 The advantages of using macro are as follows:


 Simplify and reduce the amount of repetitive coding.
 Reduce the possibility of errors caused by repetitive coding.
 Make an assembly program more readable.
MACRO SUBROUTINE
Macro name in the mnemonic field leads to Subroutine name in a call statement in the
expansion only. program leads to execution.
Macros are completely handled by the Subroutines are completely handled by the
assembler during assembly time. hardware at runtime.
Macro definition and macro expansion are The assembler knows nothing about
executed by the assembler. So, the subroutines.
assembler has to know all the features,
options, and exceptions associated with
them.
The hardware knows nothing about macros. Hardware executes the subroutine call
instruction. So, it has to know how to save
the return address and how to branch to the
subroutine.
The macro processor generates a new copy The subroutine call instruction is assembled
of the macro and places it in the program. in the usual way and treated by the
assembler as any other instruction.

Macro processing increases the size of the Use of subroutines does not result into bulk
resulting code but results in faster execution object codes but has substantial overheads
of program for expanded programs. of control transfer during execution.
Macro Preprocessors

 A preprocessor can be any program, that processes its input data to


produce output, which is used as an input to another program.

 The outputs of the macro preprocessors are assembly programs


that become inputs to the assembler.

 The macro preprocessor may exist,


 either independently and can be called during the assembling process,
 or be a part of the assembler implementation itself.
Macro Definition and Call

A macro consists of
i. a macro name,
ii. a set of formal parameters,
iii. and a body of codes.
A macro can be defined by enclosing a set of statements
between a macro header and a macro end statement.
Macro Definition and Call

The formal structure of a macro includes the following features:

1. A Macro prototype statement: Specifies the name of the macro


and name and type of formal parameters.
2. A Model statements: Specify the statements in the body of the
macro from which assembly language statements are to be
generated during expansion.
3. A Macro preprocessor statement: Specifies the statement used
for performing auxiliary functions during macro expansion
Macro Definition and Call
 A macro prototype statement can be written as follows:
<name_of_macro> [<formal parameter >
[PT]]
 where [<formal parameter spec> [PT]] defines the parameter name and its kind,
which are of the following form:
&<name_of_parameter>
[<parameter_type>]
 A macro can be called by writing the name of the macro in the mnemonic field of the
assembly language.
 The syntax of a typical macro call can be of the following form:

<name_of_macro> [<actual_parameter> [PT]]


Prototype statement: The
MACRO directive in the mnemonic
Macro Definition and Call field specifies the start of the
Macro macro definition
heade
r MACRO
 Macro Definition INCR &MEM_VAL, &INC_VAL, Formal parameters
&REG
body (model
MOVER &REG &MEM_VAL statements) of
ADD &REG &INC_VAL the macro and
they appear in
MOVEM &REG &MEM_VAL the expanded
MEND code.

The MEND directive specifies


the end of the macro
definition.

INCR A, B,
 Macro Call statement AREG
Macro Expansion Example
START 100 START 100
A DS 1 A DS 1
B DS 1 B DS 1
INCR A, B, + MOVER AREG A
AREG + ADD AREG B
PRINT A + MOVEM AREG A
STOP PRINT A
END STOP
MACRO END
INCR &MEM_VAL,
&INC_VAL, &REG Expanded
MOVER &REG &MEM_VA code
L
ADD &REG &INC_VAL
MOVEM &REG &MEM_VA
L
Macro Expansion

 A macro call in a program is an invocation of the new operation or a


new method of declaring data.

 To expand a macro, the name of the macro is placed in the operation


field, and no special directives are necessary.

 During macro expansion, the macro name statement in the program


is replaced by the sequence of assembly statements.
Macro Expansion Example
START 200 START 200
A DS 1 A DS 1
B DS 1 B DS 1
CALC A, B AREG + MOVER AREG A
PRINT A + MULT AREG B
STOP + MOVEM AREG A
END PRINT A
STOP
MACRO END
CALC &X, &Y,&REG
OP=MULT
MOVER &REG &X
OP &REG &Y
MOVEM &REG &X
MEND
Macro Expansion

There are two key notions used in implementing macro expansion:

1. Flow of control during expansion: it determines the order in which


model statements in a macro’s definition would be visited for
expansion of a macro call.

2. Lexical substitution: lexical substitution is used to generate an


assembly statement from a model statement.
1. Flow of control during expansion

 Default flow is sequential.

 A preprocessor statement can alter the flow of control during


expansion such as,
1. Conditional expansion: some model statements are not visited at all.
2. Expansion time loop: some statements are repeatedly executed.
2. Lexical substitution

 Model statement may use string of three different types.


1. An ordinary string – is retained in its original form during lexical
substitution.
2. Formal parameter preceded by &  is replaced by its value.
3. Preprocessor variable preceded by &  is replaced by its value.

 A macro prototype statement contains formal parameters.


 There are two different types of formal parameters,
1. Positional parameters
2. Keyword parameters
Types of formal parameters

1. Positional parameters
 A positional formal parameter is written as e.g.,

&<parameter name>

 The value of a positional formal parameter XYZ is determined by the rule of positional
association as follows:
 Find the ordinal position of &XYZ in the list of formal parameters in the macro prototype
statement.
 Find the actual parameter specification that occupies the same ordinal position in the list of
actual parameters in the macro call statement.
1. Positional parameters
MACRO
Positional
INCR &MEM_VAL, &INC_VAL,
parameters
&REG
MOVER &REG &MEM_VAL START 100
ADD &REG &INC_VAL A DS 1
MOVEM &REG &MEM_VAL B DS 1
MEND + MOVER AREG A
START 100 + ADD AREG B
A DS 1 + MOVEM AREG A
B DS 1 PRINT A
INCR A, B, STOP
AREG END
PRINT A
STOP Expanded
END code
Types of formal parameters

2. Keyword parameters
 For keyword parameters, the specification <parameter kind> is the
string '=' in syntax rule.
 The <actual parameter specification> is written as <formal
parameter name> = <ordinary string>.
 The value of a formal parameter is determined by the rule of
keyword association as follows:
 Find the actual parameter specification which has the form XYZ= <ordinary
string>.
 If the <ordinary string> in the specification is some string ABC, the value of
formal parameter XYZ would be ABC.
2. Keyword parameters
MACRO
INCR_M &MEM_VAL=, &INCR_VAL=, &REG=
Keyword
parameters
MOVER &REG &MEM_VAL
ADD &REG &INC_VAL
MOVEM &REG &MEM_VAL
MEND

During a macro call, a keyword parameter is


specified by its name.
INCR_ MEM_VAL=A, INCR_VAL=B,
M REG=AREG OR
INCR_ INCR_VAL=B, REG=AREG,
The order can
M MEM_VAL=A
be changed.
2. Keyword parameters
 Default value can be assigned to the keyword parameter.
 If a macro call does not explicitly specify the value of the parameter,
the preprocessor uses its default value.

MACRO
Prototype INCR_D &MEM_VAL=, &INCR_VAL=,
statemen &REG=AREG
t MOVER &REG &MEM_VAL
ADD &REG &INC_VAL
MOVEM &REG &MEM_VAL
Call MEND
statemen INCR_D MEM_VAL=A,
t OR
INCR_VAL=B
INCR_D INCR_VAL=B, REG=BREG,
MEM_VAL=A
Types of formal parameters

 Macros with mixed parameter lists


 A macro definition may use both positional and keyword parameters.
 In such a case, all positional parameters must precede all keyword parameters in
a macro call.
 For example, in the macro call

SUMUP A, B, G=20,
H=X Keyword
Positional
paramet paramet
ers ers
Nested Macro Calls

 A model statement in a macro may constitute a call on another


macro. Such a call is known as a nested macro call.

 The macro that contains the nested call as the outer macro and the
macro that is called in the nested call as the inner macro.

 The macro preprocessor performs expansion of nested macro calls


using the last-in first-out (LIFO) rule.
Nested Macro Calls
MACRO
COMPUT &FIRST, & SECOND + MOVEM BREG, TMP
E
+ MOVER BREG, X
MOVEM BREG, TMP
INCR_D &FIRST, & SECOND, + ADD BREG, Y
&REG=BREG + MOVEM BREG, X
MOVER BREG, TMP + MOVER BREG, TMP
MEND

MACRO
Expanded
code
INCR_D &MEM_VAL=, &INCR_VAL=,
&REG=BREG
MOVER &REG &MEM_VAL
ADD &REG &INC_VAL
MOVEM &REG &MEM_VAL
MEND
Nested Macro Calls
The expanded code for the call statement

COMPUTE X, Y

+ MOVEM BREG
TMP [1] + MOVER BREG, X
COMPUTE [2]
X,Y + INCR_D X, Y + ADD BREG, Y [3]
+ MOVEM BREG, X
+ MOVER BREG,TMP [4]
[5]
Advanced macro facilities

 Advanced macro facilities are aimed at supporting semantic


expansion.

 These facilities are classified as:


1. Facilities for altering flow control during expansion
2. Expansion time variables
1. Facilities for altering flow control during
expansion
 Flow control can be altered by transferring control at expansion time.

 It is achieved as,A preprocessor statement with the mnemonic AIF or AGO


 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.
 An AGO statement has the syntax:

AGO <sequencing
symbol>
 It unconditionally transfers expansion time control to the statement containing
<sequencing symbol> in its label field.
1. Facilities for altering flow control during
expansion

MACRO
EVAL &X, &Y, &Z
Conditional expansion AIF (&Y EQ &X) .ONLY
MOVER AREG, &X
SUB AREG, &Y
Unconditional ADD AREG, &Z
expansion
AGO .OVER
.ONLY MOVER AREG, &Z
.OVER MEND
2. Expansion time variable
 Expansion time variables (EV's) are variables which can only be used during the
expansion of macro calls.
 A local EV is created for use only during a particular macro call.

LCL <EV
specification>
 A global EV exists across all macro calls situated in a program and can be used in any
macro which has a declaration for it.
GBL <EV
specification>
 <EV specification> has the syntax &<EV name>, where <EV name> is an ordinary
string.
 Values of EV's can be manipulated through the preprocessor statement
SET.

< EV specification > SET <SET-
A SET statement is written as:
expression>
2. Expansion time variable
 Example MACRO
CONSTANTS
LCL &A
&A SET 1
DB &A
&A SET &A+1
DB &A
MEND
 The local EV A is created.
 The first SET statement assigns the value '1' to it.
 The first DB statement thus declares a byte constant ‘1’.
 The second SET statement assigns the value '2' to A and the second DB statement declares
a constant '2'.
Expansion time loops
 The LCL statement declares M to be a
local EV. Call statement:
 At the start of the expansion of the CLEAR B, 3
call, M is initialized to zero.
MACRO
 Expansion of the model statement
CLEAR &X, &N
MOVEM AREG, &X+&M leads to the
generation of the statement, LCL &M
MOVEM AREG, B &M SET 0
 The value of M is incremented by 1. MOVER AREG, =‘0’
 .MOR MOVE AREG, &X+&M
Condition is checked and the model
statement MOVEM.. is expanded E M
repeatedly until its value equals the &M SET &M + 1
value of N. AIF (&M NE
&N) .MORE
MEND
Design of Macro Preprocessor
 Macro preprocessors are required for processing all programs that contain
macro definitions and/or calls.
 Language translators such as assemblers and compilers cannot directly
generate the target code from the programs containing definitions and calls
for macros.
 Therefore, most language processing activities by assemblers and
compilers preprocess these programs through macro Pre-processors.
 A macro preprocessor essentially accepts an assembly program with macro
definitions and calls as its input.
 And processes it into an equivalent expanded assembly program with no
macro definitions and calls.
 The macro preprocessor output program is then passed over to an
assembler to generate the target object program.
Schematic of a macro preprocessor

A Program
Macro Pre- without Assembler
processor Macro
Definitions
and calls

Input Program with


Macro Definitions
Target Program
and Macro Calls
Tasks involved in macro expansion

1. Recognizing macro calls


2. Determining the values of formal parameters
3. Maintaining the values of expansion time variables
4. Organizing expansion time control flow
5. Determine the values of sequencing symbols
6. Perform expansion of a model statement
Tasks involved in macro expansion

1. Recognizing macro calls


 A table is maintained to store names of all macros defined in a program.
 Such a table is called Macro Name Table (MNT) in which an entry is made
for every macro definition being processed.
 During processing program statements, a match is done to compare strings
in the mnemonic field with entries in the MNT.
 A successful match in the MNT indicates that the statement is a macro
call.
Tasks involved in macro expansion

2. Determining the values of formal parameters


 The Preprocessor needs to know the names of formal parameters and
default values of keyword parameters.
 It obtains this information from macro definition and builds a table called
Parameter Default Table (PDT) to store the pairs of the form (<formal
parameter name>, <default value>) for each macro defined in the
program.
 A table called Actual Parameter Table (APT) holds the values of formal
parameters during the expansion of a macro call.
 The entry into this table will be in pair of the form (<formal parameter
name>, <value>).
Tasks involved in macro expansion

3. Maintaining the values of expansion time variables


 A table called Expansion time Variable Table (EVT) maintains information
about expansion variables in the form (<EV name>, <value>).
 It is used when a preprocessor statement or a model statement during
expansion refers to an EV.
Tasks involved in macro expansion

4. Organizing expansion time control flow


 A table called Macro Definition Table (MDT) is used to store the body of a
macro.
 The flow of control determines when a model statement from the MDT is to
be visited for expansion during macro expansion.
 MEC (Macro Expansion Counter) is defined and initialized to the first
statement of the macro body in the MDT.
 MDT is updated after an expansion of a model statement by a macro
preprocessor.
Tasks involved in macro expansion

5. Determine the values of sequencing symbols


 A table called Sequencing Symbols Table (SST) maintains information
about sequencing symbols in pairs of the form
(<sequencing symbol name>, <MDT entry #>)
 where <MDT entry #> denotes the index of the MDT entry containing the
model statement with the sequencing symbol.
 Entries are made on encountering a statement with the sequencing symbol
in their label field or on reading a reference prior to its definition.
Tasks involved in macro expansion

6. Perform expansion of a model statement


 Expansion of a model statement involves a lexical substitution for the
parameters and expansion time variables used in it.
 The expansion task has the following steps:
1. MEC points to the MDT entry that contains the model statement.
2. APT and EVT provide the values of the formal parameters and EVs, respectively.
3. SST enables identifying the model statement and defining sequencing symbol.
Data Structures of the Macro
Preprocessor
Table Fields in each entry
Macro name table (MNT) Macro name, Number of positional parameters
(#PP), Number of keyword parameters (#KP),
"Number of expansion time variables (#EV), MDT
pointer (MDTP), KPDTAB pointer (KPDTP), SSTAB
pointer (SSTP)
Parameter Name Table (PNTAB) Parameter name
EV Name Table (EVNTAB) Execution time Variable name
SS Name Table (SSNTAB) Sequencing Symbol name
Keyword Parameter Default Table Parameter name, default value
(KPDTAB)
Macro Definition Table (MDT) Label, Opcode, Operands
Expansion time Variable Table (EVTAB) Value
Actual Parameter Table (APTAB) Value
SS Table (SSTAB) MDT number of entry
Data Structures of the Macro
Preprocessor

 PNTAB and KPDTAB are constructed by processing the prototype


statement.
 Entries are added to EVNTAB and SSNTAB as declarations of
expansion time variables and definitions / references of sequencing
symbols are processed.
 MDT entries are constructed while processing the model statements
and preprocessing statements in the macro body.
 An entry is added to SSTAB when the definition of a sequencing
symbol is encountered.
 APTAB is constructed while processing a macro call.
 EVTAB is constructed at the start of macro expansion.
Parameter EV name table,
name table VALUE
Example: Data Structures
X
MACRO
N M 0
CLEARME &X, &N,
M &REG=AREG REG EVNTAB EVTAB
LCL &M PNTAB Keyword
parameter name
&M SET 0 table
MOVER &REG, =‘0’
.MOR MOVEM &REG, &X+&M 10 REG AREG
E KPDTA
&M SET &M+1 B
AIF (&M NE N) .MORE
MEND MACRO name
table
CLEARMEM MN
AREG, 10
Name #PP #K T
#EV MDT KPDT SSTP
P P P
CLEARME 2 1 1 25 10 5
Example: Data Structures
MACRO AREG Actual parameter
10 table
CLEARME &X, &N,
M &REG=AREG AREG
LCL &M
APTAB Sequential symbol
&M SET 0
name table
MOVER &REG, =‘0’
.MOR MOVEM &REG, &X+&M MORE 5 28
E
&M SET &M+1 SSNTA SSTAB
B
AIF (&M NE N) .MORE
MEND

CLEARMEM
AREG, 10
Example: Data Structures MACRO
DEFFINATION table
MD
T
ADD OPCODE OPERAND
MACRO 22 MACRO
CLEARMEM &X, &N, 23
&REG=AREG
24
LCL &M
25 (E, 1) SET 0
&M SET 0
26 MOVER (P,3), =‘0’
MOVER &REG, =‘0’
27 MOVEM (P,3), (P,1)+(E,1)
.MORE MOVEM &REG, &X+&M
28 (E, 1) SET (E,1) + 1
&M SET &M+1
29 AIF ((E,1) NE (P,2)) (S,1)
AIF (&M NE N) .MORE
30 MEND
MEND

CLEARMEM
Basic functions of Macro
Processor
I. Handling Macro Definition
 In general, a macro in a program can have only one definition, but it can
be called (expanded) many times.

 For the purpose of handling macro definitions, the macro assembler


maintains tables called Macro Name Table (MNT) and Macro Definition
Table (MDT).

 MNT is used to maintain a list of macros names defined in the program,


while MDT contains the actual definition statements (the body of macro).
Basic functions of Macro
Processor
I. Handling Macro Definition
 Macro definition handling starts with a MACRO directive in the statement.

 The assembler continually reads the definition from the source file and
saves it in the MDT.

 During this, the assembler, in most cases, will just save the definition as it
is in the MDT and not try to assemble it or execute it
Basic functions of Macro
Processor
I. Handling Macro Definition
 On encountering the MACRO directive in the source assembly program, the
assembler changes from the regular mode to a special macro definition
mode, wherein it does the following activities:
1. Analyzes the available space in the MDT
2. Reads continually the statements and writes them to the MDT until the
MEND directive is found.
3. When a MEND directive is encountered in the source file, the assembler
reverts to the normal mode.
4. If the MEND directive is missing, the assembler will stay in the macro
definition mode and continue to save program statements in the MDT
until an obvious error occurs.
Basic functions of Macro Processor

II. Handling Macro Expansion


 When an assembler encounters a source statement that is not an
instruction or a directive, it does not flag error immediately.

 The assembler will rather search the MNT and MDT for a macro with name
in the opcode file and, on locating a valid entry for it, change its mode of
operation from normal mode to macro expansion mode.
Basic functions of Macro Processor

II. Handling Macro Expansion


 The successive tasks performed in the macro expansion mode is as
follows:

1. Reading back a source statement from the MDT entry.

2. Writing the statement on the new source listing file unless it is a pass-0
directive (such as a call or definition of another macro); in that case, it is
executed immediately.

3. Repeating the previous two steps until the end of the macro is located in
the MDT.
Design of Macro Assembler

 A macro processor is functionally independent of the assembler, and


the output of the macro processor will be a part of the input into the
assembler.

 A macro processor, similar to any other assembler, scans and


processes statements.

 Often, the use of a separate macro processor for handling macro


instructions leads to less efficient program translation because many
functions are duplicated by the assembler and macro processor.
Design of Macro Assembler

 To overcome efficiency issues and avoid duplicate work by the


assembler, the macro processor is generally implemented within pass
1 of the assembler.

 The integration of macro processor and assembler is often referred to


as macro assembler.

 Such implementations will help in eliminating the overheads of


creating intermediate files, thus improving the performance of
integration by combining similar functions.
Design of Macro Assembler
Advantages of a macro Disadvantages of a macro
assembler assembler
It ensures that many The resulting pass by
functions need not be combining macro
implemented twice. processing and pass 1 of
Results in fewer overheads the assembler may be too
because many functions large and sometimes suffer
are combined and do not from core memory
need to create problems.
intermediate (temporary) The combination of macro
files. processor pass 0 and pass
It offers more flexibility in
I may sometimes increase
programming and allows
the complexity of program
the use of all assembler
translation, which may not
features in combination
be desired.
with macros.
Design of Macro Assembler

 The assembler will be in one of the three modes:


1. In the normal mode, the assembler will read statement lines
from the source file and write them to the new source file. There
is no translation or any change in the statements.
2. In the macro definition mode, the assembler will continuously
copy the source file to the MDT.
3. In the macro expansion mode, the assembler will read
statements from the MDT, substitute parameters, and write them
to the new source file. Nested macros can be implemented using
the Definition and Expansion (DE) mode.
Design Issues of Macro Preprocessor

1. Flexible data structures and databases: Several data structures


should be maintained to keep track of locations, nesting structures,
values of formal and positional parameters, and other important
information concerning the source program.

2. Attributes of macro arguments: Macro arguments used for expansion


have attributes. These attributes include count, type, length,
integer, scaling, and number attributes. Attributes can be used to
make decisions each time a macro is expanded.
Design Features of Macro Preprocessor

1. Default arguments: Many assemblers allow use of default arguments.


This means when the actual argument that binds the formal argument
is null in a certain expansion, the argument will be bound to default
value specified in the definition.

2. Numeric values of arguments: Although most macro processors treat


arguments normally as strings. Some assemblers, optionally allow
using the value, rather than the name of the argument.

3. Comments in macros: Comments are printed with macro definition, but


they might or might not be with each expansion. Some comments are
meant only for definitions, while some are expected in the expanded
code.
Design Features of Macro Processor

4. Associating macro parameters with their arguments: All macro


processors support associating macro parameters by position, name,
and numeric position in the argument list.

5. Delimiting macro parameters: Macro processors use specially defined


characters such as delimiters or a scheme where parameters can be
delimited in a general way. Characters like ';' and ‘.’ are used in many
macro processor implementations.

6. Directives related to arguments: Modern macro processors support


arguments that ease the task of writing sophisticated macros. The
directive IF-ELSE-ENDIF helps decide whether an argument is blank or
not, or whether identical or different arguments are used.
Design Features of Macro Processor

7. Automatic label generation: Directives like IRP and PRINT provide


facilities to work with labels. A pair of IRP directives defines a
sequence of lines directing the assembler to repeatedly duplicate
and assemble the sequence as many times as determined by a
compound parameter.

 Machine-independent features:
i. concatenation of macro parameters,
ii. generation of unique labels,
iii. conditional macro expansion, and
iv. keyword macro parameters.
Macro Processor Design Options

1. Recursive Macro Expansion


 For an efficient preprocessing and expansion, preprocessors use a
language that supports recursion and allows the use of variables and
data structure for recursive expansions.

2. General-purpose Macro Processors


 Modern macro processors are more generic and not restricted to any
specific language Facilities, to call and process them are possible with
macro languages.
 Although most macro are used in assembler language, they are used
with higher-level languages as well.
Macro Processor Design Options

3. Macro Processing within Language Translators


 It is essential that all macro definitions be processed, symbols be
resolved, and calls be explained before a program is sent to language
translators such as assemblers.
 Therefore, macro processing must be a preprocessing step for
language assembling.
 So, integrating macro processing within translation activity is highly
desirable.
Macro Processor Design Options

4. Line-by-Line Macro Processor


 Performing macro processing line by line enables sharing of data
structures, utility functions and procedures, and supporting diagnostic
messages.
 Line-by-line macro processor environment reads source program,
processes macro definitions, expands macro call, and finally transfers
output lines to translators like assemblers or compilers.
Pass structure of macro assembler

 Pass I
 Macro definition processing
 Entering of names and types of symbols in the SYMTAB

 Pass II
 Macro expansion
 Memory allocation and LC processing
 Processing of literals
 Intermediate code generation

 Pass III
 Target code generation
Pass structure of macro assembler

 Pass I
 Macro definition processing
 Macro expansion
 Memory allocation, LC processing and SYMTAB construction
 Processing of literals
 Intermediate code generation

 Pass II
 Target code generation
One-pass Macro Processors

 One-pass macro processors strictly require the definition of a macro


to appear always before any statements that invoke that macro in the
program.

 The important data structures required in a one-pass macro processor


are:
1. DEFTAB (Definition Table):
 used to store the macro definition including macro prototype and macro
body.
 Comment lines are not included here, and references to the parameters
use positional notations for efficiency in substituting arguments.
One-pass Macro Processors

2. ARGTAB (Argument Table):


 It maintains arguments according to their positions in the argument list.
 During expansion, the arguments from this table are substituted for the
corresponding parameters in the macro body.

2. NAMTAB (Name Table):


 this table is used to store macro names.
 It serves as an index to DEFTAB and maintains pointers that point to the
beginning and end of the macro definition in DEFTAB.
https://freestudy9.com/design-macro-
assembler/

You might also like