Module 3
Module 3
Processor
Introduction
Macro
Macro instructions (often 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.
Macros are completely handled by the Subroutines are completely handled by the
assembler during assembly time. hardware at runtime.
Macro definition and macro expansion areexecuted by Hardware executes the subroutine call instruction. So, it
the assembler. So, the assembler has to know all the has to know how to save the return address and how to
features, options, and exceptions associated with branch to the subroutine. The assembler knows nothing
them.The hardware knows nothing about macros. about subroutines.
The macro processor generates a new copy The subroutine call instruction is assembled in the usual
of the macro and places it in the program. 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 object codes but has substantial overheads
execution of program for expanded of control transfer during execution.
programs.
A macro can be defined by enclosing a set of statements between a macro header and a macro end
statement..
The formal structure of a macro includes the following features:
Macro prototype statement: Specifies the name of the macro and name and type of formal parameters.
Model statements: Specify the statements in the body of the macro from which assembly language
statements are to be generated during expansion.
Macro Call
INCR A, B
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.
INCR A, B STOP
END
Notes by Prof. Archana Naware 10
Features of Macro facility
• Conditional macros are the one which will not get expanded to the
same group of statements all the time but rather it depends on the kind
of condition being put.
2.AGO
1. It is an unconditional branch pseudo opcode or ‘goto statement’.
2. It specifies a label appearing on some other statement in the macro instruction definition.
3. These statements are directive to the macroprocessor and do not appear in macro expansion.
Example: MACRO
MACRO
ADDS &ARG1,&ARG2,&ARG3
ADD1 &ARG
L 1,&ARG ADD1 &ARG1
A 1,=F’1’ ADD1 &ARG2
ST 1,&ARG
MEND MEND
Consider the macro definition example given below, which is used to swap two numbers.
The macro named SWAP defines another macro named STORE inside it. These type of macro are called
nested macros.
♣ Two pass algorithm will make two systematic scans, or passes over the inputs text.
♣ It searches first for macro definition and saves them and then searches macro calls
because macros cannot be expanded until they are defined unlike symbols in
assemblers.
♣ Hence the first pass handles the definition and the second pass handles the macro
calls or expansions.
♣ The macro definitions are stored in MDT( macro definition table) and the names
of the macros are stored in MNT( macro name table).
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.
Notes by Prof. Archana Naware 28
SPECIFICATION OF DATA BASE FORMAT
• Used during both pass1 and pass2 but some the functions are just the reverse.
• During pass1, ALA stores the arguments in the macro definition with positional
indicator when the definition is stored in MDT .
• i.e. the ith argument is stored in the ALA as #i.
• This arrangement is in according to the order of argument in which they appear in
the MDT.
• In the pass2, when there is macro expansion, ALA fills the arguments of the
corresponding index with its appropriate argument in the call.
• Example: when LOOP INCR DATA1, DATA2, DATA3 is executed, the ALA fills the
argument fields of the corresponding index #0, #1, #2, #3 with LOOP, DATA1, DATA2 and
DATA3.