MACRO PROCESSOR

5,087 views 20 slides Mar 10, 2019
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

System Programming
MACRO PROCESSOR


Slide Content

G. H. Patel College of Engineering & Technology Subject : System Programming (2150708) Topic : Macro Processor Batch : 1D16 Prepared by: Khyati Valera (160110116059) Rutvi Vasani (160110116060) Bhavik Vashi (160110116061) Submitted to: Prof. Vinita Shah

What is macro? A macro is a unit of specification for program generation through expansion. A macro consists of a name , a set of formal parameters and body of code. The use of a macro name with a set of actual parameters is replaced by some code generated from its body. This is called macro expansion .

MACRO : Example MACRO -------- Start of definition INCR -------- Macro name A 1,DATA A 2,DATA ------Sequence of instructions to be A 3,DATA abbreviated MEND -------- End of definition

Basic Macro Processor Functions A program with macro definition & invocation Macro Processor Program without macro definition Expanded Program Assembler Object Program

NESTED MACRO CALLS A model statement in a macro may constitute a call on another macro. Such calls are known as nested macro calls. Macro containing the nested call is the outer macro and Macro called is inner macro. They follow LIFO rule. Thus, in structure of nested macro calls, expansion of latest macro call (i.e. inner macro) is completed first.

NESTED MACRO CALLS : Example

Source code MACRO ADD 1, &arg L 1, &arg A 1, = F ‘10’ ST 1, &arg MEND MACRO ADDS &arg1, &arg2, &arg3 ADD1 &arg1 ADD1 &arg2 ADD1 &arg3 MEND ADDS data1, data2, data3 data 1 DC F‘5’ data 2 DC F‘6’ data 3 DC F‘7’ END Expanded Code Level 1 Expansion of AADS ADD1 data 1 ADD1 data 2 ADD1 data 3 data DC F ‘5’ data DC F ‘6’ data DC F ‘7’ END

Expanded Code Level 2 Expansion ofADD1 L 1, data 1 A 1, = F ’10’ ST 1, data 1 L 1, data 2 A 1, = F ’10’ ST 1, data 2 L 1, data 3 A 1, = F ’10’ ST 1, data 3 data1 DC F‘5’ data2 DC F‘6’ data3 DC F‘7’ END Expanded Code Level 1 Expansion of AADS ADD1 data 1 ADD1 data 2 ADD1 data 3 data DC F ‘5’ data DC F ‘6’ data DC F ‘7’ END

ADVANCED MACRO FACILITIES Advanced macro facilities are aimed to supporting semantic expansion. Used for: performing conditional expansion of model statements and in writing expansion time loops. These facilities can be grouped into following. 1. Facilities for alteration of flow of control during expansion. 2. Expansion time variables. 3. Attributes of parameters.

AIF STATEMENT An AIF statement has the syntax AIF (<expression>) <sequencing symbol> Where <expression> is a relational expression involving ordinary strings, formal parameters and their attributes and expansion time variables. If the relational expression evaluates to true, expansion time control is transferred to the statement containing <sequencing symbol> in its label field.

AIF STATEMENT : Example MACRO &N MOVE &T,&F AIF (T'&T NE T'&F).END Statement 1 AIF (T'&T NE 'F').END Statement 2 &N ST 2,SAVEAREA Statement 3 L 2,&F ST 2,&T L 2,SAVEAREA END MEND Statement 4

AGO STATEMENT An AGO statement has the syntax AGO <sequencing symbol> Unconditionally transfers expansion time control to the statement containing <sequencing symbol> in its label field.

AGO STATEMENT : Example MACRO &NAME MOVE &T,&F AIF (T'&T EQ 'F').FIRST Statement 1 AGO .END Statement 2 . FIRST AIF (T'&T NE T'&F).END Statement 3 &NAME ST 2,SAVEAREA L 2,&F ST 2,&T L 2,SAVEAREA .END MEND Statement 4

ANOP STATEMENT An ANOP statement is written as <sequencing symbol> ANOP And simply has the effect of defining the sequencing symbol.

ANOP STATEMENT : Example MACRO &NAME MOVE &T,&F LCLC &TYPE AIF (T'&T EQ 'F').FTYPE Statement 1 &TYPE SETC 'E' Statement 2 .FTYPE ANOP Statement 3 &NAME ST&TYPE 2,SAVEAREA Statement 4 L&TYPE 2,&F ST&TYPE 2,&T L&TYPE 2,SAVEAREA MEND

Algorithm : Pass 1 Pass1 of macro processor makes a line-by-line scan over its input. Set MDTC = 1 as well as MNTC = 1. Read next line from input program. If it is a MACRO pseudo-op, the entire macro definition except this (MACRO) line is stored in MDT. The name is entered into Macro Name Table along with a pointer to the first location of MDT entry of the definition. When the END pseudo-op is encountered all the macro-definations have been processed, so control is transferred to pass2

Algorithm : Pass 2 This algorithm reads one line of input program at a time. for each Line it checks if op-code of that line matches any of the MNT entry. When match is found (i.e. when call is pointer called MDTF to corresponding macro definition stored in MDT. The initial value of MDTP is obtained from MDT index field of MNT entry. The macro expander prepares the ALA consisting of a table of dummy argument indices & corresponding arguments to the call. Reading proceeds from the MDT, as each successive line is read, The values form the argument list one substituted for dummy arguments indices in the macro defn. Reading MEND line in MDT terminates expansion of macro & scanning continues from the input file. When END pseudo-op encountered , the expanded source program is given to the assembler

  

Thank you