Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
26 views10 pages

SPOS - Unit 2 - Example of Macro

The document outlines the processes of Pass-1 and Pass-2 in macro processing, detailing the data structures involved such as Macro Definition Table (MDT), Macro Name Table (MNT), and Argument List Array (ALA). It provides examples of source programs, intermediate code, and the outputs generated after each pass, illustrating how macros are expanded and how their definitions are managed. Additionally, it includes a second example demonstrating similar processes with different macro definitions and their corresponding outputs.

Uploaded by

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

SPOS - Unit 2 - Example of Macro

The document outlines the processes of Pass-1 and Pass-2 in macro processing, detailing the data structures involved such as Macro Definition Table (MDT), Macro Name Table (MNT), and Argument List Array (ALA). It provides examples of source programs, intermediate code, and the outputs generated after each pass, illustrating how macros are expanded and how their definitions are managed. Additionally, it includes a second example demonstrating similar processes with different macro definitions and their corresponding outputs.

Uploaded by

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

Sample example

Pass-1 Data structures/ programs :


◦ Source program with macro definitions and macro calls
◦ Output file without macro definitions & with macro calls
◦ Macro Definition Table (MDT)
◦ Macro Name Table (MNT)
◦ Argument List Array (ALA)
◦ Macro Definition Table Counter (MDTC) : Integer Variable
◦ Macro Name Table Counter (MNTC): Integer Variable

Pass-2 Data structures/programs :


◦ Input file without macro definitions & with macro calls
◦ Expanded output file without macro definitions & macro calls (Free
from Macro)
◦ Refers Macro Definition Table (MDT) created by Pass-1
◦ Refers Macro Name Table (MNT) created by Pass-1
◦ Argument List Array (ALA) to map formal parameters with actual
◦ Macro Definition Table Pointer (MDTP): Integer Variable
Example:
MAC START 100
MACRO
ADD1
L AR,1
L AR,2
ST N, 1
MEND
TOTAL EQU 5
L 1,D1
SR 2,2
A 1,=F’5’
ADD1
ST 2, 1
AR TOTAL, 2
END
Output of Pass1:

Macro Name Table :

MNTC Macro Name MDTC


1 ADD1 1

Macro Definition Table :

MDTC MDT
1 ADD1
2 L AR,1

3 L AR,2

4 ST N, 1

5 MEND

Intermediate code of Pass-1


MAC START 100
TOTAL EQU 5
L 1,D1
SR 2,2
A 1,=F’5’
ADD1
ST 2, 1
AR TOTAL, 2
END

Output of Pass2:

MAC START 100


TOTAL EQU 5
L 1,D1
SR 2,2
A 1,=F’5’
L AR,1
L AR,2
ST N, 1
ST 2, 1
AR TOTAL, 2
END

Pass1
Input file: Source Code :
-MAC START 100
-MACRO
-&A0 ADD1 &A1, &A2, &A3
-&A0 L 1, &A1
-L 2, &A2
-AR 1, 2
MUL 1, &A3
ST N, 1
MEND
MACRO
SUB &P1, &P2
L 1, &P1
S 1, &P2
ST 2, 1
MEND
TOTAL EQU 5
L 1,D1
SR 2,2
A 1,=F’5’
LOOP1 ADD1 D1, D2, D3
ST 2, 1
AR TOTAL, 2
SUB X, Y
BR 14
D1 DC F’3’
D2 DC F’45’
D3 DC F’21’
X DC F’10’
Y DC F’20’
END
Pass 1: MNTC=1 MDTC=1
7
47
35
Intermediate Code after pass1:
MAC START 100
TOTALEQU 5
L 1, D1
SR 2, 2
A 1, =F’5’
ADD1 LOOP1, D1, D2, D3
ST 2, 1
AR TOTAL, 2
SUB X, Y
BR 14
D1 DC F’3’
D2 DC F’45’
D3 DC F’21’
X DC F’10’
Y DC F’20’
END

Argument List Array :


Inde Formal Args Actual Args
x
1 &A0 Loop1
2 &A1 D1
3 &A2 D2
4 &A3 D3
5 &p1 X
6 &P2 Y
7
8/4/2021
38
34

Pass 2
ALA
Inde Formal Actual
x

1 &A0 LOOP1

2 &A1 D1

3 &A2 D2

4 &A3 D3

5 &P1 X

6 &P2 Y

Intermediate Code after pass1 (input file for pass 2):

MAC START 100


TOTAL EQU 5
L 1, D1
SR 2, 2
A 1, =F’5’
ADD1 LOOP1, D1, D2, D3
ST 2, 1
AR TOTAL, 2
SUB X, Y
BR 14
D1 DC F’3’
D2 DC F’45’
D3 DC F’21’
X DC F’10’
Y DC F’20’
END
Expanded Source Code :
MAC START 100
TOTALEQU 5
L 1, D1
SR 2, 2
A 1, =F’5’
LOOP1 L 1, D1
L 2, D2
AR 1, 2
MUL 1, D3
ST N, 1
ST 2, 1
AR TOTAL, 2
L 1, X
S 1, Y
ST 2, 1

BR 14
D1 DC F’3’
D2 DC F’45’
D3 DC F’21’
X DC F’10’
Y DC F’20’
END
8/4/2021
41

Example 2
Pass1
MNTC=1
MDTC=1
Intermediate file of Pass1
PRG2 START
USING *,14
INCR1 TEMP,RES
FOUR DC F’4’
FIVE DC F’5’
RES DS 1F
TEMP DC F’2’
END

Macro Name Table :

MNTC Macro Name MDTC


1 INCR1 1

Macro Definition Table :

MDTC Macro Card


1 INCR1 &FIRST,&SECOND
2 A,1,#1
3 L,2,#2
4 ST,1,#1
5 MEND
6
Argument List Array :

Inde Formal Args Actual Args


x
1 FIRST TEMP
2 SECOND RES
2

PASS2:
Input file of pass 2
Intermediate file of Pass1
PRG2 START
USING *,14
INCR1 TEMP,RES
FOUR DC F’4’
FIVE DC F’5’
RES DS 1F
TEMP DC F’2’
END

Argument List Array :

Inde Formal Args Actual Args


x
1 FIRST TEMP
2 SECOND RES
2

Expanded code as output of Pass2

PRG2 START
USING *,14
A,1 TEMP
L,2,RES
ST,1,FIRST
FOUR DC F’4’
FIVE DC F’5’
RES DS 1F
TEMP DC F’2’
END

You might also like