macro
TRANSCRIPT
![Page 1: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/1.jpg)
MACROS
05/03/23jaya1
![Page 2: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/2.jpg)
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 MACROmacro name {Sequence to be abbreviated }End of definition MEND
05/03/23jaya2
![Page 3: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/3.jpg)
MACRO Example
::
A 1, DATAA 2, DATA
:A 1, DATAA 2, DATA
:DATA DC F’5’ 05/03/23jaya
3
![Page 4: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/4.jpg)
MACRO Example(Macro definition)Syntax exampleMACRO MACROMACRO NAME INCRINSTRUCTION 1 A 1, DATAINSTRUCTION 2 A 2, DATA...MEND MEND
05/03/23jaya4
![Page 5: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/5.jpg)
MACRO Example(Macro call)Macro call(SYNTAX) macro call(example)MACRO MACROMACRO NAME INCRINSTRUCTION 1 A 1, DATAINSTRUCTION 2 A 2, DATA::MEND MEND:INSTRUCTION A 3, DATA:MACRO NAME INCR: DATA DC F’5
05/03/23jaya5
![Page 6: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/6.jpg)
MACRO Example(Macro definition)Syntax exampleMACRO MACROMACRO NAME INCRINSTRUCTION 1 A 1, DATAINSTRUCTION 2 A 2, DATA...
05/03/23jaya6
![Page 7: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/7.jpg)
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.
05/03/23jaya7
![Page 8: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/8.jpg)
MACRO
: macro definition :LOOP1 A 1,DATA1 MACRO
A 2,DATA2 ARG0 VARY &COUNT,&ARG1,&ARG2,&ARG3A 3,DATA3 &ARG0 A 1,&ARG1: AIF (&COUNT EQ 1).FINI
LOOP2 A 1,DATA3 A 2,&ARG2A 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,DATA3DATA2 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
05/03/23jaya8
![Page 9: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/9.jpg)
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).FINIA 2,&ARG2 A 2,&ARG2AIF (&COUNT EQ 2).FINI AIF (&COUNT EQ 2).FINIA 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
DATA1 DC F’5’ :DATA2 DC F’10’ LOOP3 A 1,DATA1DATA3 DC F’15’ :
Macro callMacro expansion
05/03/23jaya9
![Page 10: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/10.jpg)
MACRO CALLS WITHIN MACROS:L 1,DATA1A 1,=F’1’ST 1,DATA1L 1,DATA2A 1,=F’1’ST 1,DATA2L 1,DATA3A 1,=F’1’ST 1,DATA3::
DATA1 DC F’5’DATA2 DC F’10’DATA3 DC F’15’
: 05/03/23jaya10
![Page 11: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/11.jpg)
MACRO CALLS WITHIN MACROSMACROADD1 &ARGL 1,&ARGA 1,=F’1’ST 1,&ARGMEND
MACROADDS &ARG1,&ARG2,&ARG3ADD1 &ARG1ADD1 &ARG2ADD1 &ARG3MEND
Macro call
05/03/23jaya11
![Page 12: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/12.jpg)
MACRO EXPANSIONSOURCE
: MACRO
ADD1 &ARGL 1,&ARGA 1,=F’1’ST 1,&ARGMENDMACROADDS &ARG1,&ARG2,
&ARG3ADD1 &ARG1 : :ADD1 &ARG2ADD1 &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,DATA2DATA3 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
05/03/23jaya12
![Page 13: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/13.jpg)
MACRO DEFINITION WITHIN MACRO DEFINITION
MACRODEFINE &SUB
MACRO&SUB &YCNOP 0,4BAL 1,*+8DC A(&Y)L 15,=V(&SUB)BALR 14,15MEND
MEND
Definition of macro &sub
DEFINITION OF
MaCRO dEFINe
05/03/23jaya13
![Page 14: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/14.jpg)
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,*+8DC A(AR)L 15,=V(COS)BALR 14,15
05/03/23jaya14
![Page 15: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/15.jpg)
IMPLEMENTATION
STATEMENT OF PROBLEM
SPECIFICATION OF DATA BASES
SPECIFICATION OF DATA BASE FORMAT
ALGORITHM05/03/23jaya15
![Page 16: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/16.jpg)
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
05/03/23jaya16
![Page 17: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/17.jpg)
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)
05/03/23jaya17
![Page 18: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/18.jpg)
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)
05/03/23jaya18
![Page 19: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/19.jpg)
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)
05/03/23jaya19
![Page 20: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/20.jpg)
PASS 1- PROCESSING MACRO DEFINITIONS
05/03/23jaya20
![Page 21: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/21.jpg)
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 TableArgument List Array
Macro Name Table
05/03/23jaya21
![Page 22: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/22.jpg)
PASS 2 – PROCESSING MACRO CALLS AND EXPANSION
05/03/23jaya22
![Page 23: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/23.jpg)
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 TableArgument List Array
Macro Name Table
05/03/23jaya23
![Page 24: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/24.jpg)
MACRO&LAB INCR &ARG1,&ARG2,&ARG3&LAB A 1,&ARG1
A 2,&ARG2A 3,&ARG3MEND||
LOOP1 INCR DATA1,DATA2,DATA3
LOOP1 A 1,DATA1
A 2, DATA2A 3,DATA3
05/03/23jaya24
![Page 25: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/25.jpg)
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
05/03/23jaya25
![Page 26: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/26.jpg)
Example with 2 macros ADDS and ADD1MACROADD1 &ARGL 1,&ARGA 1,=F’1’ST 1,&ARGMENDMACROADDS &ARG1,&ARG2,&ARG3ADD1 &ARG1ADD2 &ARG2ADD3 &ARG3MEND
05/03/23jaya26
![Page 27: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/27.jpg)
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 MEND05/03/23jaya27
![Page 28: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/28.jpg)
IMPLEMENTATION WITHIN AN ASSEMBLER
Macro processor can be added as a pre-processor to an assembler
Combining similar functions Ex- MNT+MOT/POT
05/03/23jaya28
![Page 29: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/29.jpg)
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
RR
R R
END pseudo-op
Found others
Not macro call
Not pseudo op
Found macro call
Macro pseudo op
05/03/23jaya29
![Page 30: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/30.jpg)
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
05/03/23jaya30
![Page 31: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/31.jpg)
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)
05/03/23jaya31
![Page 32: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/32.jpg)
One-pass macro processor
MDTC 1MNTC 1
MDI “OFF”MDLC 0
Search MNT for match with operation code
MDTP MDT index from MNT entry
READ
Macro name found
MDI “ON”
Set up macro call argument list array
Macro
pseudo-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 ?
MEND pseudo-
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
noyes
no
yes
no
Yes macro definition
![Page 33: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/33.jpg)
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
05/03/23jaya33
![Page 34: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/34.jpg)
One-pass macro processor
MDTC 1MNTC 1
MDI “OFF”MDLC 0
Search MNT for match with operation code
SP SP+N+2
READ
Macro 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
Macro
pseudo-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 ?
MEND pseudo-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
noyes
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
05/03/23jaya34
![Page 35: Macro](https://reader036.vdocuments.net/reader036/viewer/2022081521/587053741a28aba2118b4c85/html5/thumbnails/35.jpg)
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 ?
MDLC = 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
05/03/23jaya35