KEMBAR78
Module II (Macroprocessor) | PDF | Assembly Language | Computer Program
0% found this document useful (0 votes)
26 views77 pages

Module II (Macroprocessor)

The document discusses the concepts of macro processors, loaders, and linkers in system software and compiler design. It explains macro definitions, expansions, and the differences between macros and functions, as well as the structure of a two-pass macro processor. Additionally, it covers the use of macro instruction arguments and provides examples of macro definitions and their expansions.

Uploaded by

Eshan Jinabade
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)
26 views77 pages

Module II (Macroprocessor)

The document discusses the concepts of macro processors, loaders, and linkers in system software and compiler design. It explains macro definitions, expansions, and the differences between macros and functions, as well as the structure of a two-pass macro processor. Additionally, it covers the use of macro instruction arguments and provides examples of macro definitions and their expansions.

Uploaded by

Eshan Jinabade
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/ 77

MIT-WPU

Final Year (B.Tech)

System Software and Compiler Design

3/27/2020 1
Module II

• Macro processor: Macro Definition,


Macro expansion and nested macros
• Loaders: Loader schemes: Types of loaders,
direct linking loaders.
• Linkers: Relocation and linking
concepts, self-relocating programs, Static and
dynamic link libraries.

3/27/2020 2
Introduction to Macro
• In the mid-1950s, when assembly language programming was commonly
used to write programs for digital computers, the use of macro
instructions was initiated for two main purposes:
– to reduce the amount of program coding that had to be written by generating several
assembly language statements from one macro instruction and
– to enforce program writing standards, e.g. specifying input/output commands in
standard ways.
– Macro instructions were effectively a middle step between assembly language
programming and the high-level programming languages that followed, such
as FORTRAN and COBOL
– Eg.
– #define PI 3.14159 //"PI" to be replaced with "3.14159" wherever it occurs
– #define pred(x) ((x)-1) // What this macro expands to depends on
what argument x is passed to it. Here are some possible expansions:

• pred(2) → ((2) -1)


• pred(y+2) → ((y+2) -1)
• pred(f(5)) → ((f(5))-1)

3
Introduction
• Macro instructions (macros) are single -line abbreviations for
group of instructions.
• Macros are used to provide a program generation facility through
macro expansion.
• Many languages provide built in facilities for writing macros.
e.g. PL/I, C, Ada and C++, Assembly languages.
• Generating preprocessors or software tools like Awk of Unix has
an equivalent effect.
• A macro is a unit of specification for program generation
through expansion.

3/27/2020 4
Introduction (contd…)
Macros are defined at the start of the program.

A Macro Definition consists of


• MACRO Pseudo opcode
• Name of macro
• List of formal parameters
• Body of macro(instruction) or Sequence to be abbreviated
• MEND Pseudo opcode

Macro Definition Syntax :-


1) Macro header :- It contains keyword ‘MACRO’.
2) Macro prototype statement syntax :-
< Macro Name > [ & < Formal Parameters > ]
3) Model Statements :- It contains 1 or more simple assembly statements, which will replace
MACRO CALL while macro expansion.
4) MACRO END MARKER :- It contains keyword ‘MEND’.

3/27/2020 5
Introduction
• Macro name with a set of actual parameters, is replaced by some
code, generated from macro body. This is called macro
expansion.
• Two types of expansions:
• Lexical expansion: It implies replacement of a character string by
another character string during program generation.
• Semantic expansion: Generation of type specific instructions for
manipulation of byte and word operands.

6
Macro-processor
• Many times some blocks of code is repeated in the course of a
program
• They may consists of code
-- to save or exchange set of registers
-- to set up linkages
-- to perform a series of arithmetic operations
• In this situation macro instruction facility is useful.
• Programmer defines a single instruction to represent a block of
code.
• For every occurrence of this one line instruction the assembler will
substitute the entire block.

3/27/2020 7
Macros and Functions
Macros Functions
• Macro is Preprocessed • Function is Compiled
• No Type Checking is done in • Type Checking is done in
Macro functions
• Using Macro increases the code • Using Function keeps the code
length length unaffected
• Speed of Execution using Macro • Speed of Execution using
is Faster Function is Slower
• Before Compilation, macro name • During function call, transfer of
is replaced by macro value control takes place
• Macros are useful when small • Functions are useful when large
code is repeated many times code is to be written
• Macro does not check any • Function checks Compile-Time
Compile-Time Errors Errors
• Does not require CALL and • Requires CALL and RETURN
RETURN

3/27/2020 8
Macro Instruction
Start of definition MACRO
Macro name [ ]
Sequence to be abbreviated

End of definition MEND

Macro Example
MACRO
INCR
ADD 1,DATA
ADD 2,DATA
ADD 3,DATA
MEND
:
INCR
:
INCR

3/27/2020 9
Example of macro

10
Example-Macro
• Macro instructions are single line abbreviations for group of
instructions
e.g. EXPANDED SOURCE
A 1,DATA MACRO
A 2,DATA INCR
A 3,DATA A 1,DATA
…….. A 2,DATA
A 1,DATA A 3,DATA
A 2,DATA MEND
A 3,DATA ……… A 1,DATA
INCR A 2,DATA
………... A 3,DATA
DATA DC F’5’
………..
……… A 1,DATA
INCR A 2,DATA
………. A 3,DATA

3/27/2020 DATA DC F’5’ 11


Contd…
Source program with expanded source without
Macro definitions & macro calls definition & call

MACRO
INCR &ARG MOVER CREG,LABEL1
ADD AREG ,&ARG ADD AREG,DATA1
ADD BREG,&ARG ADD BREG,DATA1
MEND SUB CREG ,LABEL1
MOVER CREG,LABEL1
INCR DATA1
SUB CREG,LABEL1
---
---
---
3/27/2020 12
Macro features
1.Macro instruction arguments
2.Conditional macro expansion
3. Macro calls within macros
4.Macro instructions defining macros

3/27/2020 13
Macro Instruction Arguments
1.Macro instruction arguments
• Macro facility lacks in flexibility: there is no way for a specific macro call
to modify the coding that replaces it.
• So extension of this facility consists of providing for arguments or
parameters in macro call
– dummy arguments
– positional arguments
– keyword arguments
– label arguments
these arguments are preceded by &.

3/27/2020 14
Macro Instruction Arguments Contd…
e.g. Source Expanded source
…… MACRO
…… INCR &ARG
A 1,DATA1 A 1,&ARG
A 2,DATA1 A 2,&ARG
A 3,DATA1 A 3,&ARG
…… MEND
…… ……
A 1,DATA2 …… A 1,DATA1
A 2,DATA2 INCR DATA1 A 2,DATA1
A 3,DATA2 ……. A 3,DATA1
…. ……. ……..
….. INCR DATA2 A 1,DATA2
DATA1 DC F’5’ …… A 2,DATA2
DATA2 DC F’10’ …… A 3,DATA2
DATA1 DC F’5’ DATA1 DC F’5’
DATA2 DC F’10’ DATA2 DC F’10’
……
……

3/27/2020 15
Macro Instruction Arguments (Label Arguments)

MACRO Loop1 A 1,DATA1


&LAB INCR &ARG1,&ARG2,&ARG3 A 2,DATA2
&LAB A 1, &ARG1 A 3,DATA3
A 2, &ARG2
…….
A 3, &ARG3
Loop2 A 1,DATA3
MEND
A 2,DATA2
…….
LOOP1 INCR DATA1,DATA2,DATA3 A 3,DATA1
………. ………
LOOP2 INCR DATA3,DATA2,DATA1 DATA1 DC F’5’
…….. DATA2 DC F’10’
DATA1 DC F’5’ DATA3 DC F ’15’
DATA2 DC F’10’
DATA3 DC F’15’
…….

3/27/2020 16
Macro Instruction Arguments

Positional arguments
arguments are matched with dummy arguments according to the order in which they
appear

e.g. INCR A B C

Keyword arguments:
it allows reference to dummy arguments by name as well as by position
e.g. INCR &ARG1=A,&ARG3=C,&ARG2=B

3/27/2020 17
Macro Instruction Arguments (Positional Arguments)

MACRO
INCR &ARG1,&ARG2,&ARG3,&LAB
&LAB A 1, &ARG1
A 2, &ARG2
A 3, &ARG3
MEND
…….
INCR DATA1,DATA2,DATA3,LOOP1
……….
INCR DATA3,DATA2,DATA1,LOOP2
……..
DATA1 DC F’5’
DATA2 DC F’10’
DATA3 DC F’15’
…….
3/27/2020 18
2 Pass Macroprocessor

• Recognize macro definitions


• Save the definitions
• Recognize calls
• Expand calls and substitute arguments

3/27/2020 19
2 Pass Macroprocessor structure
• Pass I
1. Input macro source deck
2.Output macro source deck copy for use by pass 2
3.Macro definition table (MDT) ,used to store body of macro def.
4.Macro name table (MNT) ,used to store names of defined macros
5.MDTC-MDT counter ,used to indicate next available entry in MDT
6.MNTC-MNT counter, used to indicate next available entry in MNT
7.Argument List Array(ALA) used to substitute index markers for dummy
arguments before storing macro definition

3/27/2020 20
Example
MACRO M2 D3 D4

M1 &ARG1,&ARG2
PRINT S1
ADD AREG &ARG1
PRINT S2
ADD BREG &ARG2
S1 DC 5
MEND

MACRO S2 DC 6

M2 &ARG3,&ARG4 END
SUB AREG &ARG3
SUB BREG &ARG4
MEND
START 300
MOVER AREG S1
MOVEM BREG S2
M1 D1 D2

MOVER AREG S1
3/27/2020 21
Contd…

• Pass 2
1. Copy of input macro source deck
2. Output expanded source deck to be used as input to assembler
3. MDT, created by Pass 1
4. MNT, created by pass 1
5. MDTP- MDT pointer used to indicate next line of text to be used during
macro expansion
6. ALA ,used to substitute macro call arguments for the index markers in the
stored macro definition.

3/27/2020 22
MDT

• Macro definition table(MDT)


• Used to store macro definition Index instruction

• Created by pass-1
• Pass 1 identifies and stores all macro definitions in MDT
• Pass 2 can identify macro calls and expand these calls by using their
macro definitions stored in MDTs
• Every line of macro definition except MACRO is stored in MDT as
MACRO is not used to expand macro
• MEND indicates end of macro definition so it is stored in MDT
• MDT has 80 bytes per entry

3/27/2020 23
MNT
• Macro name table(MNT)
• Used to store name of macros and corresponding MDT index
• Created by Pass 1 and used by Pass 2
• So that pass 2 can decide whether opcode of this source instruction is
macro call or not by searching through name field of MNT.

MNT index Macro Name MDT index

• MDTC(Macro def table counter)


this variable stores the last count from the MDT table
• MNTC(Macro name table counter)
this variable stores the no. of macros defined in the program
3/27/2020 24
ALA
• Argument List Array(ALA)
• Used for association of dummy arguments and actual arguments
• Partially table is created by pass 1 where pass 1 associates an unique
integer number with each dummy arguments in the order in which they
appear
• Macros are stored in MDT by using these numbers
• It is partially constructed and used by pass 2
• It keeps track of dummy parameters when the macro is being defined and
maintain the actual arguments when expanding the call

Integer index dummy argument Actual argument

3/27/2020 25
Example
MACRO
INCR &ARG1
MOVER AREG,& ARG1
ADD AREG,& ARG1
MOVEM AREG,& ARG1
MEND

START
MOVEM BREG, A
ADD CREG,=‘1’
SUB CREG,A
INCR DATA1
MUL CREG,=‘1’
END
3/27/2020 26
Macro processor example
START 200 MDT
MACRO MDT Instruction
index
INCR &ARG1,&ARG2 1
MOVER AREG, A
ADD AREG,B
MOVEM AREG,A
MEND
MNT
MOVER AREG,=‘1’
MNT Index Macro Name MDT index
MOVEM BREG,M
1
INCR DATA1,DATA2
ALA
DATA1 DC 5
ALA Formal Argument
DATA2 DC 10 Index
END #1

3/27/2020 27
Macro processor example
START 200 MDT
MACRO MDT Instruction
index
INCR &ARG1,&ARG2 1
MOVER AREG, A
ADD AREG,B
MOVEM AREG,A
MEND
MNT
MOVER AREG,=‘1’
MNT Index Macro Name MDT index
MOVEM BREG,M
1 INCR 1
INCR DATA1,DATA2
ALA
DATA1 DC 5
ALA Formal Argument
DATA2 DC 10 Index
END #1

3/27/2020 28
Macro processor example
START 200 MDT
MACRO MDT Instruction
index
INCR &ARG1,&ARG2
MOVER AREG, A
ADD AREG,B
MOVEM AREG,A
MEND
MNT
MOVER AREG,=‘1’
MNT Index Macro Name MDT index
MOVEM BREG,M
1 INCR 1
INCR DATA1,DATA2
ALA
DATA1 DC 5
ALA Formal Argument
DATA2 DC 10 Index
END #1 &ARG1
#2 &ARG2
3/27/2020 29
Macro processor example
START 200 MDT
MACRO MDT Instruction
index
INCR &ARG1,&ARG2 1 INCR &ARG1,&ARG2
MOVER AREG, A
ADD AREG,B
MOVEM AREG,A
MEND
MNT
MOVER AREG,=‘1’
MNT Index Macro Name MDT index
MOVEM BREG,M
1 INCR 1
INCR DATA1,DATA2
ALA
DATA1 DC 5
ALA Formal Argument
DATA2 DC 10 Index
END #1 &ARG1
#2 &ARG2
3/27/2020 30
Macro processor example
START 200 MDT
MACRO MDT Instruction
index
INCR &ARG1,&ARG2 1 INCR &ARG1,&ARG2
MOVER AREG, A 2 MOVER AREG, A

ADD AREG,B
MOVEM AREG,A
MEND
MNT
MOVER AREG,=‘1’
MNT Index Macro Name MDT index
MOVEM BREG,M
1 INCR 1
INCR DATA1,DATA2
ALA
DATA1 DC 5
ALA Formal Argument
DATA2 DC 10 Index
END #1 &ARG1
#2 &ARG2
3/27/2020 31
Macro processor example
START 200 MDT
MACRO MDT Instruction
index
INCR &ARG1,&ARG2 1 INCR &ARG1,&ARG2
MOVER AREG, A 2 MOVER AREG, A
3 ADD AREG,B
ADD AREG,B
MOVEM AREG,A
MEND
MNT
MOVER AREG,=‘1’
MNT Index Macro Name MDT index
MOVEM BREG,M
1 INCR 1
INCR DATA1,DATA2
ALA
DATA1 DC 5
ALA Formal Argument
DATA2 DC 10 Index
END #1 &ARG1
#2 &ARG2
3/27/2020 32
Macro processor example
START 200 MDT
MACRO MDT Instruction
index
INCR &ARG1,&ARG2 1 INCR &ARG1,&ARG2
MOVER AREG, A 2 MOVER AREG, A
3 ADD AREG,B
ADD AREG,B
4 MOVEM AREG,A
MOVEM AREG,A
MEND
MNT
MOVER AREG,=‘1’
MNT Index Macro Name MDT index
MOVEM BREG,M
1 INCR 1
INCR DATA1,DATA2
ALA
DATA1 DC 5
ALA Formal Argument
DATA2 DC 10 Index
END #1 &ARG1
#2 &ARG2
3/27/2020 33
Macro processor example
START 200 MDT
MACRO MDT Instruction
index
INCR &ARG1,&ARG2 1 INCR &ARG1,&ARG2
MOVER AREG, A 2 MOVER AREG, A
3 ADD AREG,B
ADD AREG,B
4 MOVEM AREG,A
MOVEM AREG,A
5 MEND
MEND
MNT
MOVER AREG,=‘1’
MNT Index Macro Name MDT index
MOVEM BREG,M
1 INCR 1
INCR DATA1,DATA2
ALA
DATA1 DC 5
ALA Formal Argument
DATA2 DC 10 Index
END #1 &ARG1
#2 &ARG2
3/27/2020 34
Output of Pass 1
MDT
MDT Instruction
index
Output file
1 INCR &ARG1,&ARG2
2 MOVER AREG, A
START 200
3 ADD AREG,B
MOVER 4 MOVEM AREG,A
AREG,=‘1’
5 MEND
MOVEM BREG,M
MNT
INCR
DATA1,DATA2 MNT Index Macro Name MDT index
DATA1 DC 5 1 INCR 1
DATA2 DC 10
ALA
END
ALA Formal Argument
Index
#1 &ARG1
#2 &ARG2
3/27/2020 35
Output of Pass 2
MDT
MDT Instruction
index
1 INCR &ARG1,&ARG2
Final 2 MOVER AREG, A
Expansion
3 ADD AREG,B
START 200
4 MOVEM AREG,A
MOVER 5 MEND
AREG,=‘1’
MOVEM BREG,M MNT

MOVER AREG, A MNT Index Macro Name MDT index


1 INCR 1
ADD AREG,B

MOVEM AREG,A ALA

DATA1 DC 5 ALA Formal Argument


Index
DATA2 DC 10 #1 &ARG1
END #2 &ARG2

3/27/2020 36
Contd…
MACRO
&LAB INCR &ARG1,&ARG2,&ARG3
&LAB MOVER AREG, &ARG1
A DD AREG, &ARG2
MOVEM BREG, &ARG3
MEND
…….
LOOP1 INCR DATA1,DATA2,DATA3
……….
LOOP2 INCR DATA3,DATA2,DATA1
……..
DATA1 DC F’5’
DATA2 DC F’10’
DATA3 DC F’15’
3/27/2020 37
…….
Example Contd…
• MDT ALA
Index arguments
Index instruction
#0 “LOOP1BBB”
1 &LAB INCR &ARG1,&ARG2,&ARG3
#1 “DATA1BBB”
2 #0 MOVER AREG,#1
#2 “DATA2BBB”
3 ADD AREG,#2
#3 “DATA3BBB”
4 MOVEM BREG ,#3
5 MEND

• MNT ALA
Index arguments
Index Name(8 bytes) MDT index (4 bytes) #0 “BBBBBBB”
1 “INCRbbbb” 1 #1 “DATA3BBB”
#2 “DATA2BBB”
#3 “DATA1BBB”

3/27/2020 38
3/27/2020 39
3/27/2020 40
Contd..
START
……..
MACRO
INCR &ARG1,&ARG2,&ARG3
A 1, &ARG1
A 2, &ARG2
A 3, &ARG3
MEND
…….
INCR DATA1,DATA2,DATA3
……….
INCR DATA3,DATA2,DATA1
……..
DATA1 DC F’5’
DATA2 DC F’10’
DATA3 DC F’15’
…….
END
3/27/2020 41
Contd…
START
MOVER AREG,A
MOVEM AREG,B
……
MACRO
VARY &ARG1,&ARG2
L 1,F’5’
A 1,&ARG1
A 1,&ARG2
MEND
MACRO
INCR &ARG1,&ARG2,&ARG3
A 1, &ARG1
A 2, &ARG2
A 3, &ARG3
MEND
…….
INCR DATA1,DATA2,DATA3
……….
VARY DATA3,DATA2
……..
DATA1 DC F’5’
DATA2 DC F’10’
DATA3 DC F’15’
…….
END

3/27/2020 42
Conditional macro expansion

MACRO
&ARG0 VARY &COUNT,&ARG1,&ARG2,&ARG3
&ARG0 A 1, &ARG1
A IF (&COUNT EQ 1).FINI TEST IF &COUNT=1
A 2, &ARG2
A IF (&COUNT EQ 2).FINI TEST IF &COUNT=2
A 3, &ARG3
.FINI MEND
…….
LOOP1 VARY 3, DATA1,DATA2,DATA3
……….
LOOP2 VARY 2, DATA3,DATA2
……..
LOOP3 VARY 1, DATA1

DATA1 DC F’5’
DATA2 DC F’10’
DATA3 DC F’15’
…….

3/27/2020 43
…… Expanded code
Loop1 A 1,DATA1
A 2,DATA2
A 3,DATA3
…….
Loop2 A 1,DATA3
A 2,DATA2
………
Loop1 A 1,DATA1
…….
DATA1 DC F’5’
DATA2 DC F’10’
DATA3 DC F ’15’

3/27/2020 44
Contd…
• Pseudo opcodes AIF & AGO
• .FINI (labels starting with a period(.) are macro labels )and do not appear
in the output of the macro processor
• AIF (conditional branch pseudo opcodes)
• AGO (unconditional branch pseudo opcodes ) or goto statement.
• AIF & AGO control the sequence in which the macro processor expands
the statements in macro instruction

3/27/2020 45
Macro instructions defining macros

MACRO
DEFINE &SUB macro name: DEFINE
MACRO
&SUB &Y dummy macro name
CNOP 0,4
Def.of def of macro BAL 1,*+8 set register 1 to parameter list ptr
Macro &SUB DC A(&Y) parameter list ptr
define L 15,=V(&SUB) address of subroutine
BALR 14,15 transfer control to subroutine
MEND
MEND
…..
…..
DEFINE COS outer macro
…..
……
COS AR inner macro

3/27/2020 46
A single pass algorithm for macro processor
• MDI : macro definition input indicator
works like switch
keeps track of macro call
MDI is ON
-during expansion of a macro call
-lines are read from MDT
MDI is OFF
all other times
--the reading of MEND line indicates end of macro and terminates expansion of a call ,MDI is
set off next line is obtained from regular i/p stream.

• MDLC : macro definition level counter


-- keeps track of macro definition.
-- MDLC is incremented by 1 when a MACRO is encountered and
decremented by 1 when MEND occurs
-- MDLC is used to insure that the entire macro def. including MACROs
& MENDs get stored in MDT

3/27/2020 47
MDT
Index instructions
START MNT
1
….
MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB
1
MACRO
&SUB &Y
CNOP 0,4
BAL 1,*+8 ALA
DC A(&Y)
ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 x
MEND #1
MEND
…..
…..
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 48
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB
1 DEFINE 1
MACRO
&SUB &Y 2
CNOP 0,4
BAL 1,*+8 ALA
DC A(&Y)
ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 x
MEND #1 &SUB
MEND
….. #2
…..
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 49
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3
1 DEFINE 1
MACRO
&SUB &Y 2
CNOP 0,4
BAL 1,*+8 ALA
DC A(&Y)
ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 x
MEND #1 &SUB
MEND
….. #2
…..
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 50
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4
&SUB &Y 2
CNOP 0,4
BAL 1,*+8 ALA
DC A(&Y)
ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 x
MEND #1 &SUB COS
MEND
#2
…..
…..
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 51
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2
5
CNOP 0,4
BAL 1,*+8 ALA
DC A(&Y)
ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 x
MEND #1 &SUB
MEND
….. #2
…..
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 52
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2
5 BAL 1,*+8
CNOP 0,4 6
BAL 1,*+8 ALA
DC A(&Y)
ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 x
MEND #1 &SUB
MEND
….. #2
…..
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 53
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7
DC A(&Y)
ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 x
MEND #1 &SUB
MEND
….. #2
…..
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 54
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 5 BAL 1,*+8 2
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 x
MEND #1 &SUB
MEND
….. #2
…..
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 55
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 BALR 14,15 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 9 x
MEND 10 #1 &SUB
MEND
11 #2
…..
….. 12
DEFINE COS
13
…..
…… 14
COS AR 15
…….
16
END
17
3/27/2020 56
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 BALR 14,15 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 9 MEND x
MEND 10 #1 &SUB COS
MEND
#2
…..
…..
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 57
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2 COS 11
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 BALR 14,15 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 9 MEND x
MEND 10 MEND #1 &SUB COS
MEND 11 #2
…..
12
…..
DEFINE COS 13
….. 14
……
COS AR 15
……. 16
END
17
3/27/2020 58
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 BALR 14,15 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 9 MEND x
MEND 10 MEND #1 &SUB COS
MEND 11 #2
…..
…..
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 59
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2 COS 11
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 BALR 14,15 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 9 MEND x
MEND 10 MEND #1 &SUB COS
MEND 11 COS &Y #2 &Y
….. 12
…..
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 60
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2 COS 11
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 BALR 14,15 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 9 MEND x
MEND 10 MEND #1 &SUB COS
MEND 11 COS &Y #2 &Y
….. 12 CNOP 0,4
…..
13
DEFINE COS
…..
……
COS AR
…….
END

3/27/2020 61
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2 COS 11
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 BALR 14,15 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 9 MEND x
MEND 10 MEND #1 &SUB COS
MEND 11 COS &Y #2 &Y
….. 12 CNOP 0,4
…..
13 BAL 1,*+8
DEFINE COS
….. 14
……
COS AR
…….
END

3/27/2020 62
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2 COS 11
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 BALR 14,15 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 9 MEND x
MEND 10 MEND #1 &SUB COS
MEND 11 COS &Y #2 &Y
….. 12 CNOP 0,4
…..
13 BAL 1,*+8
DEFINE COS
….. 14 DC A(#2)
…… 15
COS AR
…….
END

3/27/2020 63
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2 COS 11
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 BALR 14,15 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 9 MEND x
MEND 10 MEND #1 &SUB COS
MEND 11 COS &Y #2 &Y
….. 12 CNOP 0,4
…..
13 BAL 1,*+8
DEFINE COS
….. 14 DC A(#2)
…… 15 L 15,=V(COS)
COS AR 16
…….
END

3/27/2020 64
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2 COS 11
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 BALR 14,15 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 9 MEND x
MEND 10 MEND #1 &SUB COS
MEND 11 COS &Y #2 &Y
….. 12 CNOP 0,4
…..
13 BAL 1,*+8
DEFINE COS
….. 14 DC A(#2)
…… 15 L 15,=V(COS)
COS AR 16 BALR 14,15
……. 17
END

3/27/2020 65
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2 COS 11
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y) ALA Formal Actual
8 BALR 14,15 Inde Argument Argument
L 15,=V(&SUB)
9 MEND x
BALR 14,15
MEND 10 MEND #1 &SUB COS
MEND 11 COS &Y #2 &Y
….. 12 CNOP 0,4
…..
13 BAL 1,*+8
DEFINE COS
….. 14 DC A(#2) Expansion of Define
15 L 15,=V(COS) Cos call
……
COS AR 16 BALR 14,15
……. 17 MEND
END

3/27/2020 66
MDT
Index instructions
START MNT
1 DEFINE &SUB
….
2 MACRO MNT MACRO MDT
MACRO INDEX NAME INDEX
DEFINE &SUB 3 #1 &Y
1 DEFINE 1
MACRO 4 CNOP 0,4
&SUB &Y 2 COS 11
5 BAL 1,*+8
CNOP 0,4 6 DC A(&Y)
BAL 1,*+8 ALA
7 L 15,=V(#1)
DC A(&Y)
8 BALR 14,15 ALA Formal Actual
L 15,=V(&SUB) Inde Argument Argument
BALR 14,15 9 MEND
x
MEND 10 MEND
#1 &SUB COS
MEND 11 COS &Y
#2 &Y AR
….. 12 CNOP 0,4
….. Expansion of COS AR
13 BAL 1,*+8
DEFINE COS call
14 DC A(#2)
…..
…… 15 L 15,=V(COS)
CNOP 0,4
COS AR 16 BALR 14,15
BAL 1,*+8
……. 17 MEND DC A(#2)
END L 15,=V(COS)
BALR 14,15
3/27/2020 67
Macro calls within macros
MACRO
ADD1 &ARG
MOVER AREG, &ARG
ADD AREG, =‘1’
MOVEM AREG,&ARG
MEND

MACRO
ADDS &ARG1,&ARG2,&ARG3
ADD1 &ARG1
ADD1 &ARG2
ADD1 &ARG3
MEND
……
ADDS DATA1,DATA2,DATA3
……
DATA1 DC F’5’
DATA2 DC F’10’
DATA3 DC F’15’
……..

3/27/2020 68
Contd…
Source expanded source expanded source
level 1 level 2

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 expansion of ADDSexpansion of ADD1
MEND
……. L 1,DATA1
…… ADD1 DATA1 A 1,F’1’
ST 1,DATA1
ADDS DATA1,DATA2,DATA3 ADD1 DATA 2 L 1,DATA2
A 1,F’1’
…… ADD1 DATA3 ST 1,DATA2
…… L 1,DATA3
DATA1 DC F’5’ A 1,F’1’
DATA2 DC F’10’ ST 1,DATA3
DATA3 DC F’15’
END
3/27/2020 69
START
…..
…..
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
……
ADDS DATA1,DATA2,DATA3
……
DATA1 DC F’5’
DATA2 DC F’10’
DATA3 DC F’15’
……..
END
3/27/2020 70
START Index instructions
…..
….. 1 ADD1 &ARG
MACRO
2 L 1,#1
ADD1 &ARG
L 1,&ARG 3 A 1,F’1’
A 1,F’1’
4 ST 1 ,#1
ST 1,&ARG
MEND 5 MEND
….
6 ADDS &ARG1,&ARG2,&ARG3
MACRO
ADDS &ARG1,&ARG2,&ARG3 7 ADD1 #1
ADD1 &ARG1
ADD1 &ARG2 8 ADD1 #2
ADD1 &ARG3 9 ADD1 #3
MEND
…… 10 MEND
ADDS DATA1,DATA2,DATA3
MNT INDEX MACRO MDT INDEX
……
NAME
DATA1 DC F’5’
1 ADD1 1
DATA2 DC F’10’
DATA3 DC F’15’ 2 ADDS 6
……..
END
3/27/2020 71
• Consider the following code ,show the contents of MNT,MDT.
START 100
SR 2,2
USING *,15
MACRO
XYZ &A
A 1,&A
AR 2,2
MEND
L 1,D1
MACRO
ABC &Z
SR 3,3
MACRO
DISPLAY
XYZ B
MEND
L 1,&Z
MEND
XYZ B1
SR 4,4
ABC B1
D1 DC F’4’
B1 DC F’5’
END
2/18/2025 72
• Consider the following code ,show the contents of MNT,MDT.
START 100
SR 2,2 INDEX INSTRUCTION INDEX NAME MDT
USING *,15 1 XYZ &A INDEX
MACRO 1 XYZ 1
2 A 1,#1
XYZ &A
3 AR 2,2 2 ABC 5
A 1,&A
AR 2,2 4 MEND 3 DISPLAY 13
MEND 5 ABC &Z
L 1,D1
6 SR 3,3
MACRO
ABC &Z 7 MACRO
SR 3,3 8 DISPLAY
MACRO ALA DUMMY ACTUAL
9 XYZ B INDEX ARG ARG
DISPLAY
XYZ B 10 MEND #1 &A B1
MEND 11 L 1,#2
#2 &Z B1
L 1,&Z
12 MEND
MEND
XYZ B1 13 DISPLAY
SR 4,4 14 XYZ B
ABC B1
15 MEND
D1 DC F’4’
2/18/2025 73
B1 DC F’5’
Consider the following program, show the content of MNT,MDT
START
AR 2,3
SR 4,4
MACRO
M1 &S1
AR 3,3
MACRO
&S1 &X
SR 4,4
L 1,F’4’
DC A(&X)
L 2,V(&S1)
BALR 14,15
MEND
MEND
AR 1,1
M1 PQR
SR 2,2
PQR T
END

2/18/2025 74
Consider the following program, show the content of MNT,MDT
START
1 M1 &S1
AR 2,3 MNT NAME MDT
2 AR 3,3
SR 4,4 INDEX INDEX
3 MACRO
MACRO 1 M1 1
4 #1 &X
M1 &S1 2 PQR 12
5 SR 4,4
AR 3,3
6 L 1 ,F’4’
MACRO
7 DC A(&X)
&S1 &X
8 L 2,V(#1)
SR 4,4
9 BALR 14,15
L 1,F’4’
10 MEND
DC A(&X)
11 MEND
L 2,V(&S1)
12 PQR &X
BALR 14,15
13 SR 4,4
MEND
14 L 1,F’4’
MEND
15 DC A(T)
AR 1,1
16 L 2,V(PQR)
M1 PQR
17 BALR 14,15
SR 2,2
18 MEND
PQR T
2/18/2025 75
END
Contd…
• MDTP= 6 when ADDS is called
• And MDI is set ON .
• Then READ function increments MDTP , gets line from the MDT(line 7)
• Then MDTP = MDTP+1 =7
• So it is ADD1 DATA1
Then MDTP =1 so here previous value of MDTP i.e. 7 will be lost.
This the problem with macro calls within macros
• So it will work recursively.
• means to process one macro before it is finished with another then to
continue with the previous or outer.
• Recursive procedures usually operate by means of stack.
• Each stack frame is associated with each recursive call
• Here status of unfinished computations is preserved.

3/27/2020 76
References
• System Programming & Operating System - TE
: Macro Definition and call, Nested Macro Call
s, (wikinote.org)

77

You might also like