MACROS
11/15/2016jaya
1
MACRO
 Macro instructions are single-line abbreviations for group of
instructions.
 Macro is an abbreviation for a sequence of operations .
 Syntax/structure
start of definition MACRO
macro name {
Sequence to be abbreviated }
End of definition MEND
11/15/2016jaya
2
MACRO
 Example
:
:
A 1, DATA
A 2, DATA
:
A 1, DATA
A 2, DATA
:
DATA DC F’5’ 11/15/2016jaya
3
MACRO
 Example(Macro definition)
Syntax example
MACRO MACRO
MACRO NAME INCR
INSTRUCTION 1 A 1, DATA
INSTRUCTION 2 A 2, DATA
.
.
.
MEND MEND
11/15/2016jaya
4
MACRO Example(Macro call)
Macro call(SYNTAX) macro call(example)
MACRO MACRO
MACRO NAME INCR
INSTRUCTION 1 A 1, DATA
INSTRUCTION 2 A 2, DATA
:
:
MEND MEND
:
INSTRUCTION A 3, DATA
:
MACRO NAME INCR
: DATA DC F’5
11/15/2016jaya
5
MACRO
 Example(Macro definition)
Syntax example
MACRO MACRO
MACRO NAME INCR
INSTRUCTION 1 A 1, DATA
INSTRUCTION 2 A 2, DATA
.
.
.
11/15/2016jaya
6
CONDITIONAL MACRO EXPANSION
 Two pseudo-ops are used
 AIF:- It is conditional branch pseudo-op that performs an
arithmetic test and branches to specified macro-label only if test is
true.
 AGO:- It is unconditional branch pseudo-op. It is equivalent to go-
to statement.
 .FINI:- Labels starting with a period(.), such as .FINI, are macro
label do not appear in the output of the macro processor.
11/15/2016jaya
7
MACRO
: macro definition :
LOOP1 A 1,DATA1 MACRO
A 2,DATA2 ARG0 VARY &COUNT,&ARG1,&ARG2,&ARG3
A 3,DATA3 &ARG0 A 1,&ARG1
: AIF (&COUNT EQ 1).FINI
LOOP2 A 1,DATA3 A 2,&ARG2
A 2,DATA2 AIF (&COUNT EQ 2).FINI
: A 3,&ARG3
LOOP3 A 1,DATA1 .FINI MEND
: macro call :
DATA1 DC F’5’ LOOP1 VARY 3,DATA1,DATA2,DATA3
DATA2 DC F’10’ :
DATA3 DC F’15’ LOOP2 VARY 2,DATA3,DATA2
: :
LOOP3 VARY 1,DATA1
:
DATA1 DC F’5’
DATA2 DC F’10’
DATA3 DC F’15’
Pgm with macro definition
(macro call)
example
11/15/2016jaya
8
MACRO
: :
MACRO MACRO
&ARG0 VARY &COUNT,&ARG1,&ARG2,&ARG3 &ARGO VARY &COUNT,&ARG1,&ARG2,&ARG3
&ARG0 A 1,&ARG1 &ARG0 A 1,&ARG1
AIF (&COUNT EQ 1).FINI AIF (&COUNT EQ 1).FINI
A 2,&ARG2 A 2,&ARG2
AIF (&COUNT EQ 2).FINI AIF (&COUNT EQ 2).FINI
A 3,&ARG3 A 3.&ARG3
.FINI MEND .FINI MEND 3,&ARG3
: :
LOOP1 VARY 3,DATA1,DATA2,DATA3 LOOP1 A 1,DATA1
: A 2,DATA2
LOOP2 VARY 2,DATA3,DATA2 A 3,DATA3
: :
LOOP3 VARY 1,DATA1 LOOP2 A 1,DATA3
: A 2,DATA2
DATA1DC F’5’ :
DATA2DC F’10’ LOOP3 A 1,DATA1
DATA3DC F’15’ :
Macro call
Macro expansion
11/15/2016jaya
9
MACRO CALLS WITHIN MACROS
:
L 1,DATA1
A 1,=F’1’
ST 1,DATA1
L 1,DATA2
A 1,=F’1’
ST 1,DATA2
L 1,DATA3
A 1,=F’1’
ST 1,DATA3
:
:
DATA1 DC F’5’
DATA2 DC F’10’
DATA3 DC F’15’
:
11/15/2016jaya
10
MACRO CALLS WITHIN MACROS
MACRO
ADD1 &ARG
L 1,&ARG
A 1,=F’1’
ST 1,&ARG
MEND
MACRO
ADDS &ARG1,&ARG2,&ARG3
ADD1 &ARG1
ADD1 &ARG2
ADD1 &ARG3
MEND
Macro call
11/15/2016jaya
11
MACRO EXPANSION
SOURCE
:
MACRO
ADD1 &ARG
L 1,&ARG
A 1,=F’1’
ST 1,&ARG
MEND
MACRO
ADDS &ARG1,&ARG2,
&ARG3
ADD1 &ARG1 : :
ADD1 &ARG2
ADD1 &ARG3 L 1,DATA1
: ADD1 DATA1 A 1,=F’1’
: ST 1,DATA1
: L 1,DATA2
: ADD1 DATA2 A 1,=F’1’
ADDS DATA1,DATA2, ST 1,DATA2
DATA3 ADD1 DATA3 L 1,DATA3
A 1,=F’1’
: ST 1,DATA3
:
:
: :
: :
DATA1 DC F’5’ DATA1 DC F’5’
DATA2 DC F’10’ DATA2 DC F’10’
DATA3 DC F’15’ DATA3 DC F’15’
Expanded
source of
ADDS
Expanded
source of
ADD1
11/15/2016jaya
12
MACRO DEFINITION WITHIN MACRO DEFINITION
MACRO
DEFINE &SUB
MACRO
&SUB &Y
CNOP 0,4
BAL 1,*+8
DC A(&Y)
L 15,=V(&SUB)
BALR 14,15
MEND
MEND
D
e
f
i
n
i
t
i
o
n
o
f
m
a
c
r
o
&
s
u
b
D
E
F
I
N
I
T
I
O
N
O
F
Ma
C
R
O
d
E
F
I
N
e
11/15/2016jaya
13
MACRO DEFINITION WITHIN MACRO
DEFINITION
 Inner macro will not be defined until outer macro is called.
 Macro call sequence
 DEFINE COS
 The statement expands into a new macro definition
 COS AR
 The macro processor will generate the calling sequence:
BAL 1,*+8
DC A(AR)
L 15,=V(COS)
BALR 14,15
11/15/2016jaya
14
IMPLEMENTATION
STATEMENT OF PROBLEM
SPECIFICATION OF DATA BASES
SPECIFICATION OF DATA BASE FORMAT
ALGORITHM
11/15/2016jaya
15
STATEMENT OF PROBLEM
 Macro processor is a system program which accepts an assembly
language program with macro definition and macro calls and produce
an equivalent assembly language program in which all macro calls are
expanded.
 Four basic tasks of macro instruction processor
 Recognize macro definitions
 Save the definition
 Recognize calls
 Expand calls and substitute arguments
11/15/2016jaya
16
STATEMENT OF PROBLEM
 Macro processor performs expansion using 2 passes
 Pass I
 It examines every operation code
 Save all macro definitions in a macro definition table
and macro name table
 Save a copy of the input text , minus macro definition
 Pass II
 Identify macro calls
 Replace each macro name with the appropriate text
from macro definition(expand macro call)
11/15/2016jaya
17
SPECIFICATION OF DATA BASE
 PASS I
 The input macro source deck
 Output macro source deck copy for use by pass2
 Macro Definition Table(MDT)
 Macro Name Table(MNT)
 Macro Definition Table Counter(MDNTC)
 Macro Name Table Counter(MNTC)
 Argument List Array(ALA)
11/15/2016jaya
18
SPECIFICATION OF DATA BASE
 PASS II
 The copy input macro source deck
 Output expanded source deck copy for use by
assembler
 Macro Definition Table(MDT) created by pass1
 Macro Name Table(MNT) created by pass1
 Macro Definition Table Pointer(MDNTP)
 Argument List Array(ALA)
11/15/2016jaya
19
PASS 1- PROCESSING MACRO
DEFINITIONS
11/15/2016jaya
20
EXAMPLE
MACRO
&LAB INCR &ARG1,&ARG2,&ARG3
&LAB A 1,&ARG1
A 2,&ARG2
A 3,&ARG3
MEND
|
|
INCR
Index Contents(80 bytes per entry)
5 &LAB INCR &ARG1,&ARG2,&ARG3
6 #0 A 2,#1
7 A 3,#2
8 A 2,#3
9 MEND
10
INDEX NAME(8
bytes)
0 #0(&LAB)
1 #1(&ARG1)
2 #2(&ARG2)
3 #3(&ARG3)
INDEX NAME( 8
bytes
MDT
POSITION(
4 bytes)
1 INCR 5
2
3
Macro Definition Table
Argument List Array
Macro Name Table
11/15/2016jaya
21
PASS 2 – PROCESSING MACRO CALLS AND EXPANSION
11/15/2016jaya
22
EXAMPLE
MACRO
&LAB INCR &ARG1,&ARG2,&ARG3
&LAB A 1,&ARG1
A 2,&ARG2
A 3,&ARG3
MEND
|
|
LOOP1 INCR DATA1,DATA2,DATA3
Index Contents ( 80 bytes per entry)
5 &LAB INCR &ARG1,&ARG2,&ARG3
6 #0 A 2,#1
7 A 3,#2
8 A 2,#3
9 MEND
10
INDEX NAME (
8 bytes)
0 “LOOP1bbb”
1 “DATA1bbb”
2 “DATA2bbb”
3 “DATA3bbb”
INDEX NAME ( 8 bytes) MDT
POSITION
( 4 byte)
1 “INCRbbb” 5
2
3
Macro Definition Table
Argument List Array
Macro Name Table
11/15/2016jaya
23
MACRO
&LAB INCR &ARG1,&ARG2,&ARG3
&LAB A 1,&ARG1
A 2,&ARG2
A 3,&ARG3
MEND
|
|
LOOP1 INCR DATA1,DATA2,DATA3
LOOP1 A 1,DATA1
A 2, DATA2
A 3,DATA3
11/15/2016jaya
24
IMPLEMENTATION OF MACRO
CALL WITHIN MACRO
 Basic problem in implementing macro calls within
macros is “recursion”
 Need to expand both macro
 Each call might be expanded by another macro
 More macros vs single macro
11/15/2016jaya
25
 Example with 2 macros ADDS and ADD1
MACRO
ADD1 &ARG
L 1,&ARG
A 1,=F’1’
ST 1,&ARG
MEND
MACRO
ADDS &ARG1,&ARG2,&ARG3
ADD1 &ARG1
ADD2 &ARG2
ADD3 &ARG3
MEND
11/15/2016jaya
26
 MDT(Macro Definition Table)
Index Contents
1 ADD1 &ARG
2 L 1,#1
3 A 1,=F’1’
4 ST 1,#1
5 MEND
6 ADDS &ARG1,&ARG2,&ARG3
7 ADD1 #1
8 ADD2 #2
9 ADD3 #3
10 MEND
11/15/2016jaya
27
IMPLEMENTATION WITHIN AN
ASSEMBLER
 Macro processor can be added as a pre-processor to
an assembler
 Combining similar functions
 Ex- MNT+MOT/POT
11/15/2016jaya
28
MACRO PROCESSOR COMBINED WITH
ASSEMBLER PASS 1
PASS 1!
Search Pseudo-Op Table
(POT)!
Search Macro Name Table
(MNT)!!
GO TO PASS2!
Search Machine -Op Table
(MOT)!
Process machine instruction
Type?
Process macro definition
Set up macro stack frame ,
etc.
Process pseudo-ops
READ *R
R
R
R R
END pseudo-op
Found
others
Not macro call
Not pseudo op
Found macro call
Macro pseudo op
11/15/2016jaya
29
ADVANTAGES & DISADVANTAGES
OF INCORPORATING MACRO INTO
PASS1
 Advantages
 functions do not have to implemented twice
 Less overhead during processing
 More flexible for programmer
 Disadvantages
 Large program
 More complex
11/15/2016jaya
30
SINGLE PASS ALGORITHM
 Problem of macro definition with macros
 Combine pass1 and pass2
 Two additional variables
 MDI(Macro Definition Input) indicator
 MDLC(Macro Definition Level Counter)
11/15/2016jaya
31
One-pass macro processor
MDTC  1
MNTC  1
MDI  “OFF”
MDLC  0
Search MNT for match with
operation code
MDTP  MDT index from MNT
entry
READ
Macr
o
name
found
MDI  “ON”
Set up macro call argument list array
Macr
o
pseu
do-op
?
READ*
Enter macro name & current value of
MDTC in MNT entry number MNTC
MNTC  MNTC+1
Prepare macro definition argument list
array
Enter macro name card into MDT
MDTC MDTC+1
MDLC MDLC+1
READ*
MDTC MDTC+1
Substitute index notation for argument
in definition
Enter line into MDT
Macro
pseudo
-op ?
MEN
D
pseud
o-op ?
MDLC MDLC+1
MDLC MDLC-1
MDLC
 0 ?
MNTC  MNTC+1
END
Pseudo
-op?
Supply expanded source file to
processing
a
a
a
no
Yes macro call
no
no
yes
yes
no
yes
no
yes
no
Yes macro definition
READ *
subroutine
MDI =
“OFF”
?
Read next source card from
input file
Return to main processing
Increment MDT pointer to
next entry MDTP 
MDTP + 1
MDI  “OFF”
Get next card from MDT
Substitute arguments from
macro call
Process AIF or AGO set new value
to MDTP
MDLC
= 0 ?
MEND
pseudo-
op ?
AIF
or
AGO
?
yes
yes
yes
yes
No within
macro call
no
no
no
Detail of read function used
for macro expansion
11/15/2016jaya
33
One-pass macro processor
MDTC  1
MNTC  1
MDI  “OFF”
MDLC  0
Search MNT for match with
operation code
SP  SP+N+2
READ
Macr
o
name
found
S(SP+N+2) SP
Set up macro call argument list
array in S(SP+2)---- S(SP+N+1)
where N = total number of
arguments
Macr
o
pseu
do-
op ?
READ*
Enter macro name & current value of
MDTC in MNT entry number MNTC
Prepare macro definition argument list
array
Enter macro name card into MDT
MDLC MDLC+1
READ*
Substitute index notation for
argument in definition
Enter line into MDT
Macro
pseudo
-op ?
MEN
D
pseud
o-op ?
MDLC MDLC+1
MDLC MDLC-1
MDLC
 0 ?
MNTC  MNTC+1
END
Pseudo
-op?
Supply expanded source file to
processing
a
a
a
no
Yes macro call
no
no
yes
yes
no
yes
no
yes
no
Yes macro definition
S(SP+1) MDT index from MNT
entry
b
b
b
One pass macro processor capable
of handling macro calls within macro
definitions
11/15/2016jaya
34
READ *
subroutine
SP = -
1
Read next source card from
input file
Return to main processing
Increment MDT pointer to
next entry S(SP+1)+1
Get next card from MDT ;
pointer is S(SP+1)
Substitute arguments from macro
call S(SP+2)…S(SP+N+1)
N  SP – S(SP)-2
AIF or
AGO ? MEND
pseudo-
op ?
MDL
C = 0
?
yes
yes
yes
No within
macro call
no
no
yes
Process AIF or AGO set new value
to MDTP
SP  S(SP)
yes
no
b
b
Detail of read
function for
recursive
macro
expansion
11/15/2016jaya
35

More Related Content

PPTX
Unit 4 sp macro
PPTX
Assemblers
PPTX
Macro Processor
PDF
Unit 3
PDF
Coal 21- macro in Assembly Programming
PPTX
System Programing Unit 1
PDF
Lecture 01 introduction to compiler
PPTX
System Programming Unit II
Unit 4 sp macro
Assemblers
Macro Processor
Unit 3
Coal 21- macro in Assembly Programming
System Programing Unit 1
Lecture 01 introduction to compiler
System Programming Unit II

What's hot (20)

PPTX
Unit iv(simple code generator)
PDF
Macro-processor
PPTX
Design of a two pass assembler
PPTX
Decomposition technique In Software Engineering
PPTX
Data transfer and manipulation
PPTX
Phases of Compiler
PPTX
Loaders ( system programming )
PPT
Introduction to Compiler design
PPTX
Context model
PPTX
MACRO PROCESSOR
PPTX
Introduction To Computer Programming
PPTX
Unit 3 sp assembler
PPTX
Code optimization
PPT
Assembly language
PPTX
Intro to assembly language
PPTX
System software - macro expansion,nested macro calls
PPTX
System programming
PPTX
Types of Compilers
PDF
Machine language
PPTX
Direct linking loaders
Unit iv(simple code generator)
Macro-processor
Design of a two pass assembler
Decomposition technique In Software Engineering
Data transfer and manipulation
Phases of Compiler
Loaders ( system programming )
Introduction to Compiler design
Context model
MACRO PROCESSOR
Introduction To Computer Programming
Unit 3 sp assembler
Code optimization
Assembly language
Intro to assembly language
System software - macro expansion,nested macro calls
System programming
Types of Compilers
Machine language
Direct linking loaders
Ad

Viewers also liked (17)

PPTX
Compilers
PPTX
PPTX
Assembler1
PPT
Cp0675 03 may-2012-rm04
PPT
PPTX
Lecture 4 assembly language
PPT
OMD chapter 2 Class modelling
PPT
PPT
SAS Macros
PPT
PPT
Assembly Language Lecture 2
PDF
Introduction to systems programming
PPT
Assembly language programming_fundamentals 8086
PPTX
Advanced behavioral modeling chapter 4 of omd
PPTX
Architectural modeling chapter 5 of omd
PPT
Assembly Language Lecture 3
PPTX
Two pass Assembler
Compilers
Assembler1
Cp0675 03 may-2012-rm04
Lecture 4 assembly language
OMD chapter 2 Class modelling
SAS Macros
Assembly Language Lecture 2
Introduction to systems programming
Assembly language programming_fundamentals 8086
Advanced behavioral modeling chapter 4 of omd
Architectural modeling chapter 5 of omd
Assembly Language Lecture 3
Two pass Assembler
Ad

Similar to Macro (20)

PPTX
Unit ii-111206004636-phpapp01
PPTX
SPOS UNIT 2 MACRO NOTES SPOS UNIT 2 MACRO NOTESSPOS UNIT 2 MACRO NOTESSPOS...
PPTX
Macro assembler
PPT
Macros in system programing
PDF
Handout#05
PDF
Unit 2
PDF
handout6.pdf
PPTX
Presentation on macros and macro processor
PDF
33443223 system-software-unit-iv
PDF
Module 5.pdf
PPTX
System Programming Unit II
PDF
Handout#04
PPT
Macro
PPTX
Chap6 procedures & macros
DOC
Chapter 5 notes new
PPT
ELENA MICROPROCESSOR
DOC
Chapter 6 notes
DOC
Excel Vba Basic Tutorial 1
PPTX
Elena Macro Processor
PPTX
MACRO ASSEBLER
Unit ii-111206004636-phpapp01
SPOS UNIT 2 MACRO NOTES SPOS UNIT 2 MACRO NOTESSPOS UNIT 2 MACRO NOTESSPOS...
Macro assembler
Macros in system programing
Handout#05
Unit 2
handout6.pdf
Presentation on macros and macro processor
33443223 system-software-unit-iv
Module 5.pdf
System Programming Unit II
Handout#04
Macro
Chap6 procedures & macros
Chapter 5 notes new
ELENA MICROPROCESSOR
Chapter 6 notes
Excel Vba Basic Tutorial 1
Elena Macro Processor
MACRO ASSEBLER

Recently uploaded (20)

PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
Applications of Equal_Area_Criterion.pdf
PDF
Soil Improvement Techniques Note - Rabbi
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PPTX
mechattonicsand iotwith sensor and actuator
PPTX
Principal presentation for NAAC (1).pptx
PDF
Java Basics-Introduction and program control
PPTX
Module 8- Technological and Communication Skills.pptx
PPTX
Amdahl’s law is explained in the above power point presentations
PDF
Unit1 - AIML Chapter 1 concept and ethics
PDF
20250617 - IR - Global Guide for HR - 51 pages.pdf
PPTX
Information Storage and Retrieval Techniques Unit III
PPTX
CyberSecurity Mobile and Wireless Devices
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
Exploratory_Data_Analysis_Fundamentals.pdf
Applications of Equal_Area_Criterion.pdf
Soil Improvement Techniques Note - Rabbi
August -2025_Top10 Read_Articles_ijait.pdf
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
mechattonicsand iotwith sensor and actuator
Principal presentation for NAAC (1).pptx
Java Basics-Introduction and program control
Module 8- Technological and Communication Skills.pptx
Amdahl’s law is explained in the above power point presentations
Unit1 - AIML Chapter 1 concept and ethics
20250617 - IR - Global Guide for HR - 51 pages.pdf
Information Storage and Retrieval Techniques Unit III
CyberSecurity Mobile and Wireless Devices
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf

Macro

  • 2. MACRO  Macro instructions are single-line abbreviations for group of instructions.  Macro is an abbreviation for a sequence of operations .  Syntax/structure start of definition MACRO macro name { Sequence to be abbreviated } End of definition MEND 11/15/2016jaya 2
  • 3. MACRO  Example : : A 1, DATA A 2, DATA : A 1, DATA A 2, DATA : DATA DC F’5’ 11/15/2016jaya 3
  • 4. MACRO  Example(Macro definition) Syntax example MACRO MACRO MACRO NAME INCR INSTRUCTION 1 A 1, DATA INSTRUCTION 2 A 2, DATA . . . MEND MEND 11/15/2016jaya 4
  • 5. MACRO Example(Macro call) Macro call(SYNTAX) macro call(example) MACRO MACRO MACRO NAME INCR INSTRUCTION 1 A 1, DATA INSTRUCTION 2 A 2, DATA : : MEND MEND : INSTRUCTION A 3, DATA : MACRO NAME INCR : DATA DC F’5 11/15/2016jaya 5
  • 6. MACRO  Example(Macro definition) Syntax example MACRO MACRO MACRO NAME INCR INSTRUCTION 1 A 1, DATA INSTRUCTION 2 A 2, DATA . . . 11/15/2016jaya 6
  • 7. CONDITIONAL MACRO EXPANSION  Two pseudo-ops are used  AIF:- It is conditional branch pseudo-op that performs an arithmetic test and branches to specified macro-label only if test is true.  AGO:- It is unconditional branch pseudo-op. It is equivalent to go- to statement.  .FINI:- Labels starting with a period(.), such as .FINI, are macro label do not appear in the output of the macro processor. 11/15/2016jaya 7
  • 8. MACRO : macro definition : LOOP1 A 1,DATA1 MACRO A 2,DATA2 ARG0 VARY &COUNT,&ARG1,&ARG2,&ARG3 A 3,DATA3 &ARG0 A 1,&ARG1 : AIF (&COUNT EQ 1).FINI LOOP2 A 1,DATA3 A 2,&ARG2 A 2,DATA2 AIF (&COUNT EQ 2).FINI : A 3,&ARG3 LOOP3 A 1,DATA1 .FINI MEND : macro call : DATA1 DC F’5’ LOOP1 VARY 3,DATA1,DATA2,DATA3 DATA2 DC F’10’ : DATA3 DC F’15’ LOOP2 VARY 2,DATA3,DATA2 : : LOOP3 VARY 1,DATA1 : DATA1 DC F’5’ DATA2 DC F’10’ DATA3 DC F’15’ Pgm with macro definition (macro call) example 11/15/2016jaya 8
  • 9. MACRO : : MACRO MACRO &ARG0 VARY &COUNT,&ARG1,&ARG2,&ARG3 &ARGO VARY &COUNT,&ARG1,&ARG2,&ARG3 &ARG0 A 1,&ARG1 &ARG0 A 1,&ARG1 AIF (&COUNT EQ 1).FINI AIF (&COUNT EQ 1).FINI A 2,&ARG2 A 2,&ARG2 AIF (&COUNT EQ 2).FINI AIF (&COUNT EQ 2).FINI A 3,&ARG3 A 3.&ARG3 .FINI MEND .FINI MEND 3,&ARG3 : : LOOP1 VARY 3,DATA1,DATA2,DATA3 LOOP1 A 1,DATA1 : A 2,DATA2 LOOP2 VARY 2,DATA3,DATA2 A 3,DATA3 : : LOOP3 VARY 1,DATA1 LOOP2 A 1,DATA3 : A 2,DATA2 DATA1DC F’5’ : DATA2DC F’10’ LOOP3 A 1,DATA1 DATA3DC F’15’ : Macro call Macro expansion 11/15/2016jaya 9
  • 10. MACRO CALLS WITHIN MACROS : L 1,DATA1 A 1,=F’1’ ST 1,DATA1 L 1,DATA2 A 1,=F’1’ ST 1,DATA2 L 1,DATA3 A 1,=F’1’ ST 1,DATA3 : : DATA1 DC F’5’ DATA2 DC F’10’ DATA3 DC F’15’ : 11/15/2016jaya 10
  • 11. MACRO CALLS WITHIN MACROS MACRO ADD1 &ARG L 1,&ARG A 1,=F’1’ ST 1,&ARG MEND MACRO ADDS &ARG1,&ARG2,&ARG3 ADD1 &ARG1 ADD1 &ARG2 ADD1 &ARG3 MEND Macro call 11/15/2016jaya 11
  • 12. MACRO EXPANSION SOURCE : MACRO ADD1 &ARG L 1,&ARG A 1,=F’1’ ST 1,&ARG MEND MACRO ADDS &ARG1,&ARG2, &ARG3 ADD1 &ARG1 : : ADD1 &ARG2 ADD1 &ARG3 L 1,DATA1 : ADD1 DATA1 A 1,=F’1’ : ST 1,DATA1 : L 1,DATA2 : ADD1 DATA2 A 1,=F’1’ ADDS DATA1,DATA2, ST 1,DATA2 DATA3 ADD1 DATA3 L 1,DATA3 A 1,=F’1’ : ST 1,DATA3 : : : : : : DATA1 DC F’5’ DATA1 DC F’5’ DATA2 DC F’10’ DATA2 DC F’10’ DATA3 DC F’15’ DATA3 DC F’15’ Expanded source of ADDS Expanded source of ADD1 11/15/2016jaya 12
  • 13. MACRO DEFINITION WITHIN MACRO DEFINITION MACRO DEFINE &SUB MACRO &SUB &Y CNOP 0,4 BAL 1,*+8 DC A(&Y) L 15,=V(&SUB) BALR 14,15 MEND MEND D e f i n i t i o n o f m a c r o & s u b D E F I N I T I O N O F Ma C R O d E F I N e 11/15/2016jaya 13
  • 14. MACRO DEFINITION WITHIN MACRO DEFINITION  Inner macro will not be defined until outer macro is called.  Macro call sequence  DEFINE COS  The statement expands into a new macro definition  COS AR  The macro processor will generate the calling sequence: BAL 1,*+8 DC A(AR) L 15,=V(COS) BALR 14,15 11/15/2016jaya 14
  • 15. IMPLEMENTATION STATEMENT OF PROBLEM SPECIFICATION OF DATA BASES SPECIFICATION OF DATA BASE FORMAT ALGORITHM 11/15/2016jaya 15
  • 16. STATEMENT OF PROBLEM  Macro processor is a system program which accepts an assembly language program with macro definition and macro calls and produce an equivalent assembly language program in which all macro calls are expanded.  Four basic tasks of macro instruction processor  Recognize macro definitions  Save the definition  Recognize calls  Expand calls and substitute arguments 11/15/2016jaya 16
  • 17. STATEMENT OF PROBLEM  Macro processor performs expansion using 2 passes  Pass I  It examines every operation code  Save all macro definitions in a macro definition table and macro name table  Save a copy of the input text , minus macro definition  Pass II  Identify macro calls  Replace each macro name with the appropriate text from macro definition(expand macro call) 11/15/2016jaya 17
  • 18. SPECIFICATION OF DATA BASE  PASS I  The input macro source deck  Output macro source deck copy for use by pass2  Macro Definition Table(MDT)  Macro Name Table(MNT)  Macro Definition Table Counter(MDNTC)  Macro Name Table Counter(MNTC)  Argument List Array(ALA) 11/15/2016jaya 18
  • 19. SPECIFICATION OF DATA BASE  PASS II  The copy input macro source deck  Output expanded source deck copy for use by assembler  Macro Definition Table(MDT) created by pass1  Macro Name Table(MNT) created by pass1  Macro Definition Table Pointer(MDNTP)  Argument List Array(ALA) 11/15/2016jaya 19
  • 20. PASS 1- PROCESSING MACRO DEFINITIONS 11/15/2016jaya 20
  • 21. EXAMPLE MACRO &LAB INCR &ARG1,&ARG2,&ARG3 &LAB A 1,&ARG1 A 2,&ARG2 A 3,&ARG3 MEND | | INCR Index Contents(80 bytes per entry) 5 &LAB INCR &ARG1,&ARG2,&ARG3 6 #0 A 2,#1 7 A 3,#2 8 A 2,#3 9 MEND 10 INDEX NAME(8 bytes) 0 #0(&LAB) 1 #1(&ARG1) 2 #2(&ARG2) 3 #3(&ARG3) INDEX NAME( 8 bytes MDT POSITION( 4 bytes) 1 INCR 5 2 3 Macro Definition Table Argument List Array Macro Name Table 11/15/2016jaya 21
  • 22. PASS 2 – PROCESSING MACRO CALLS AND EXPANSION 11/15/2016jaya 22
  • 23. EXAMPLE MACRO &LAB INCR &ARG1,&ARG2,&ARG3 &LAB A 1,&ARG1 A 2,&ARG2 A 3,&ARG3 MEND | | LOOP1 INCR DATA1,DATA2,DATA3 Index Contents ( 80 bytes per entry) 5 &LAB INCR &ARG1,&ARG2,&ARG3 6 #0 A 2,#1 7 A 3,#2 8 A 2,#3 9 MEND 10 INDEX NAME ( 8 bytes) 0 “LOOP1bbb” 1 “DATA1bbb” 2 “DATA2bbb” 3 “DATA3bbb” INDEX NAME ( 8 bytes) MDT POSITION ( 4 byte) 1 “INCRbbb” 5 2 3 Macro Definition Table Argument List Array Macro Name Table 11/15/2016jaya 23
  • 24. MACRO &LAB INCR &ARG1,&ARG2,&ARG3 &LAB A 1,&ARG1 A 2,&ARG2 A 3,&ARG3 MEND | | LOOP1 INCR DATA1,DATA2,DATA3 LOOP1 A 1,DATA1 A 2, DATA2 A 3,DATA3 11/15/2016jaya 24
  • 25. IMPLEMENTATION OF MACRO CALL WITHIN MACRO  Basic problem in implementing macro calls within macros is “recursion”  Need to expand both macro  Each call might be expanded by another macro  More macros vs single macro 11/15/2016jaya 25
  • 26.  Example with 2 macros ADDS and ADD1 MACRO ADD1 &ARG L 1,&ARG A 1,=F’1’ ST 1,&ARG MEND MACRO ADDS &ARG1,&ARG2,&ARG3 ADD1 &ARG1 ADD2 &ARG2 ADD3 &ARG3 MEND 11/15/2016jaya 26
  • 27.  MDT(Macro Definition Table) Index Contents 1 ADD1 &ARG 2 L 1,#1 3 A 1,=F’1’ 4 ST 1,#1 5 MEND 6 ADDS &ARG1,&ARG2,&ARG3 7 ADD1 #1 8 ADD2 #2 9 ADD3 #3 10 MEND 11/15/2016jaya 27
  • 28. IMPLEMENTATION WITHIN AN ASSEMBLER  Macro processor can be added as a pre-processor to an assembler  Combining similar functions  Ex- MNT+MOT/POT 11/15/2016jaya 28
  • 29. MACRO PROCESSOR COMBINED WITH ASSEMBLER PASS 1 PASS 1! Search Pseudo-Op Table (POT)! Search Macro Name Table (MNT)!! GO TO PASS2! Search Machine -Op Table (MOT)! Process machine instruction Type? Process macro definition Set up macro stack frame , etc. Process pseudo-ops READ *R R R R R END pseudo-op Found others Not macro call Not pseudo op Found macro call Macro pseudo op 11/15/2016jaya 29
  • 30. ADVANTAGES & DISADVANTAGES OF INCORPORATING MACRO INTO PASS1  Advantages  functions do not have to implemented twice  Less overhead during processing  More flexible for programmer  Disadvantages  Large program  More complex 11/15/2016jaya 30
  • 31. SINGLE PASS ALGORITHM  Problem of macro definition with macros  Combine pass1 and pass2  Two additional variables  MDI(Macro Definition Input) indicator  MDLC(Macro Definition Level Counter) 11/15/2016jaya 31
  • 32. One-pass macro processor MDTC  1 MNTC  1 MDI  “OFF” MDLC  0 Search MNT for match with operation code MDTP  MDT index from MNT entry READ Macr o name found MDI  “ON” Set up macro call argument list array Macr o pseu do-op ? READ* Enter macro name & current value of MDTC in MNT entry number MNTC MNTC  MNTC+1 Prepare macro definition argument list array Enter macro name card into MDT MDTC MDTC+1 MDLC MDLC+1 READ* MDTC MDTC+1 Substitute index notation for argument in definition Enter line into MDT Macro pseudo -op ? MEN D pseud o-op ? MDLC MDLC+1 MDLC MDLC-1 MDLC  0 ? MNTC  MNTC+1 END Pseudo -op? Supply expanded source file to processing a a a no Yes macro call no no yes yes no yes no yes no Yes macro definition
  • 33. READ * subroutine MDI = “OFF” ? Read next source card from input file Return to main processing Increment MDT pointer to next entry MDTP  MDTP + 1 MDI  “OFF” Get next card from MDT Substitute arguments from macro call Process AIF or AGO set new value to MDTP MDLC = 0 ? MEND pseudo- op ? AIF or AGO ? yes yes yes yes No within macro call no no no Detail of read function used for macro expansion 11/15/2016jaya 33
  • 34. One-pass macro processor MDTC  1 MNTC  1 MDI  “OFF” MDLC  0 Search MNT for match with operation code SP  SP+N+2 READ Macr o name found S(SP+N+2) SP Set up macro call argument list array in S(SP+2)---- S(SP+N+1) where N = total number of arguments Macr o pseu do- op ? READ* Enter macro name & current value of MDTC in MNT entry number MNTC Prepare macro definition argument list array Enter macro name card into MDT MDLC MDLC+1 READ* Substitute index notation for argument in definition Enter line into MDT Macro pseudo -op ? MEN D pseud o-op ? MDLC MDLC+1 MDLC MDLC-1 MDLC  0 ? MNTC  MNTC+1 END Pseudo -op? Supply expanded source file to processing a a a no Yes macro call no no yes yes no yes no yes no Yes macro definition S(SP+1) MDT index from MNT entry b b b One pass macro processor capable of handling macro calls within macro definitions 11/15/2016jaya 34
  • 35. READ * subroutine SP = - 1 Read next source card from input file Return to main processing Increment MDT pointer to next entry S(SP+1)+1 Get next card from MDT ; pointer is S(SP+1) Substitute arguments from macro call S(SP+2)…S(SP+N+1) N  SP – S(SP)-2 AIF or AGO ? MEND pseudo- op ? MDL C = 0 ? yes yes yes No within macro call no no yes Process AIF or AGO set new value to MDTP SP  S(SP) yes no b b Detail of read function for recursive macro expansion 11/15/2016jaya 35