0% found this document useful (0 votes)
8 views30 pages

MACROS

This document provides an overview of macros and macro processors, detailing their definitions, features, and the design of a two-pass macro processor. It explains how macros function similarly to procedures in programming, including parameter passing techniques and conditional assembly. The document also outlines the implementation and databases used during the macro processing stages.

Uploaded by

Ayushi Warke
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)
8 views30 pages

MACROS

This document provides an overview of macros and macro processors, detailing their definitions, features, and the design of a two-pass macro processor. It explains how macros function similarly to procedures in programming, including parameter passing techniques and conditional assembly. The document also outlines the implementation and databases used during the macro processing stages.

Uploaded by

Ayushi Warke
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/ 30

MODULE 3

MACROS AND MACRO PROCESSOR


CONTENTS:

• Introduction,

• Macro definition and call,

• Features of Macro facility: Simple, parameterized, conditional and


nested.

• Design of Two pass macro processor and data structures used.


Introduction
• Macros are very similar to procedures but follow a different syntax and
accept parameters.

• Macros are very similar to functions that are available in most high-level
programming languages.
Definition:
• Macro is defined to be single line abbreviation for group of instructions.

• Format :
MACRO <name>
--------

--------

--------

MEND
Macro Definition

Macro Call
OBJECT CODE
MACRO PARAMETERS
Example:
FEATURES OF MACRO
1. PARAMETERIZED
2. CONDITIONAL ASSEMBLY
3. NESTED MACRO CALLS.
PARAMETER PASSING TECHNIQUES
POSITIONAL PASSING KEYWORD PASSING
PARAMETERIZED
CONDITIONAL ASSEMBLY

LOAD R
NESTED MACRO CALL
FUNCTIONS OF MACRO-PROCESSOR SAMPLE PROGRAM

• Recognize the macro definition.


• Store the macro definition.
• Recognize the macro call.
• Perform macro expansion.
FORWARD REFERENCE PROBLEM
FORWARD REFERENCE PROBLEM SOLUTION
2 PASS MACRO PROCESSOR SPECIFICATION
• A macro processor, like an assembler, scans and processes lines of text.

• The macro processor algorithm will make two systematic scans or passes over the
input text, searching first for macro definitions and then for macro calls.

• The assembler cannot process a reference to a symbol before its definitions, in the
same way the macro processor cannot expand a macro call before having and
saved the corresponding macro definition.

• Thus we need two pass over the input text, one to handle definitions and one to
handle macro calls.
IMPLEMENTATION OF MACROPROCESSOR
1. Recognize macro definitions
Macro processor must recognize macro definitions identified by the MACRO and MEND
pseudo operations.
2. Save the definitions
Macro definitions should be saved in MACRO DEFINITION TABLE (MDT)
3. Recognize calls
The processor must recognize macro calls that appear as operation mnemonics.
4. Expand calls and substitute arguments
The processor must substitute for dummy argument corresponding arguments from a macro
call.
SPECIFICATION OF DATABASES
• Pass1 database
1. Input source

2. The macro name table (MNT) used to store the names of


defined macros.

3. MDT used to store the body of the macro definitions.

5. The macro name table counter(MNTC)used to indicate


the next available entry in the MNT

4. The macro definition table counter (MDTC) used to


indicate the next available entry in the MDT.

6. The Argument List Array (ALA) used to substitute index


markers for dummy arguments before storing a macro
definition.
Pass 2 database
1. Expanded source output

2. MDT created by pass 1

3. MNT created by pass 1

4. MDTP used to indicate the next line of text to be used during macro
expansion.

5. The ALA used to substitute macro call arguments for the index markers in
the stored macro definition.
P1: Recognise macro definition and MNT
store macro definition MNTC INDEX MACRO NAME MDT INDEX
1 INCR 1
MNTC 2

MDT
INDEX MACRO DEFINITION
1 INCR &ARG1, &ARG2, &ARG3=DATA3,
MDTC
&ARG4=DATA4
MDTC 2 A 1 #1
3 A 2 #2
4 A 3 #3
5 A 4 #4
ALA ALA
6 MEND
INDEX ARGUMENTS INDEX ARGUMENTS
1 &ARG1 1 DATA1 P2: Recognise macro call and
2 &ARG2 2 DATA9 expand macro definition
3 &ARG3 3 DATA2
4 &ARG4 4 DATA6
Example 2: MNT
INDEX MACRO NAME MDT INDEX
MACRO MNTC 1
&LAB INCR &ARG1, &ARG2,&ARG3
&LAB ADD AREG , &ARG1 MDT
ADD AREG , &ARG2 INDEX MACRO DEFINITION
MDTC
ADD AREG, &ARG3 1
MEND 2
3
START
4
LOOP INCR A,B,C
5
LABEL INCR DATA1, DATA2, DATA3 6
A DC 2 ALA
B DC 2
INDEX ARGUMENTS
C DS 2
DATA1 DC 3
DATA2 DS 2
DATA3 DC 4
END
Example 2: MNT
INDEX MACRO NAME MDT INDEX
MACRO MNTC 1 INCR 1
&LAB INCR &ARG1, &ARG2,&ARG3 MNTC
&LAB ADD AREG , &ARG1 MDT
ADD AREG , &ARG2 INDEX MACRO DEFINITION
MDTC
ADD AREG, &ARG3 1 &LAB INCR &ARG1, &ARG2,&ARG3
MDTC 2 #1 ADD AREG #2
MEND
MDTC 3 ADD AREG #3
START
4 ADD AREG #4
LOOP INCR A,B,C
5 MEND
LABEL INCR DATA1, DATA2, DATA3 6
A DC 2 ALA
B DC 2
INDEX ARGUMENTS
C DS 2
DATA1 DC 3 1 &LAB
DATA2 DS 2 2 &ARG1
DATA3 DC 4 3 &ARG2
END 4 &ARG3
Example 2: MNT
MACRO INDEX MACRO NAME MDT INDEX
&LAB INCR &ARG1, 1 INCR 1
&ARG2,&ARG3
&LAB ADD AREG , &ARG1 MDT
ADD AREG , &ARG2 INDEX MACRO DEFINITION
ADD AREG, &ARG3 1 &LAB INCR &ARG1, &ARG2,&ARG3
MEND 2 #1 ADD AREG #2
START START 3 ADD AREG #3
LOOP INCR A,B,C LOOP INCR A,B,C 4 ADD AREG #4

LABEL INCR DATA1, DATA2, LABEL INCR DATA1, 5 MEND


DATA3 DATA2, DATA3 6
A DC 2 A DC 2 ALA
B DC 2 B DC 2 INDEX ARGUMENTS
C DS 2 C DS 2 1 &LAB
DATA1 DC 3 DATA1 DC 3
2 &ARG1
DATA2 DS 2 DATA2 DS 2
DATA3 DC 4 DATA3 DC 4 3 &ARG2
END END 4 &ARG3
PASS 1→ PASS2
MNT
INDEX MACRO NAME MDT INDEX
INTERMEDIATE CODE EXPANDED CODE MNTC
1 INCR 1
START START
LOOP INCR A,B,C LOOP AREG A,B,C
ADD AREG B
MDT
ADD AREG C INDEX MACRO DEFINITION
1 &LAB INCR &ARG1, &ARG2,&ARG3
LABEL INCR DATA1, LABLE AREG 2 #1 ADD AREG #2
DATA2, DATA3 DATA1,DATA2,DATA3 3 ADD AREG #3
ADD AREG DATA2 4 ADD AREG #4
A DC 2 ADD AREG DATA3
B DC 2 5 MEND
MDTC
C DS 2 6
DATA1 DC 3 A DC 2 ALA
B DC 2 ALA
DATA2 DS 2 INDEX ARGUMENTS
C DS 2 INDEX ARGUMENTS
DATA3 DC 4
DATA1 DC 3 1 &LAB 1 LOOP LABEL
END
DATA2 DS 2 2 &ARG1 2 A DATA1
DATA3 DC 4 3 &ARG2 3 B DATA2
END
4 &ARG3 4 C DATA3
PASS 1→ PASS2
MNT
INDEX MACRO NAME MDT INDEX
INTERMEDIATE CODE EXPANDED CODE MNTC
1 INCR 1
START START
LOOP INCR A,B,C LOOP AREG A,B,C MDT
ADD AREG B INDEX MACRO DEFINITION
ADD AREG C
1 &LAB INCR &ARG1, &ARG2,&ARG3
2 #1 ADD AREG #2
LABEL INCR DATA1, LABLE AREG
DATA2, DATA3 DATA1,DATA2,DATA3 3 ADD AREG #3
ADD AREG DATA2 4 ADD AREG #4
A DC 2 ADD AREG DATA3 5 MEND
B DC 2 MDTC
C DS 2 6
DATA1 DC 3 A DC 2 ALA ALA
DATA2 DS 2 B DC 2 INDEX ARGUMENTS
INDEX ARGUMENTS
DATA3 DC 4 C DS 2 1 &LAB
DATA1 DC 3 1 LOOP
END 2 &ARG1
DATA2 DS 2 2 A
DATA3 DC 4 3 &ARG2
3 B
END 4 &ARG3
4 C
PASS-1 FLOWCHART PASS-1 MP
READ NEXT CARD
READ NEXT CARD
MNTC 1
MDTC 1 Enter Macro name
along with entry of Substitute index
MDTC in MNT notation for
READ NEXT CARD Arguments

MNTC MNTC+1
ENTER LINE IN MDT
MACRO YES
Pseudo
Op? Prepare ALA
MDTC MDTC+1

NO
Write Copy of Enter Macro name
Source card card in MDT MEND NO
Pseudo
Op?

NO END MDTC MDTC+1


Pseudo YES
Op?

Yes PASS
2
Goto PASS 2
PASS-2
R
READ From COPY MDTP MDT Index from MNT
FILE

SEARCH MNT for Setup ALA


match with
Opcode
MDTP MDTP+1

MACRO YES GET LINE FROM MDT


NAME
FOUND
?

SUBSTITUTE ARGUMENTS FROM


NO MACRO CALL
Write Expanded
Source card(ESC)
END
YES
Supply ESC to
Pseudo
Op? ASSEMBLER
END
NO Pseudo
Op?
NO
Yes
Supply ESC to R
ASSEMBLER

You might also like