You are on page 1of 6

Nashik District Maratha Vidya Prasarak Samaj’s

Karmaveer Adv. Baburao Ganpatrao Thakare College of Engineering, Nashik-13


Department of Electronics & Telecommunication Engineering

Experiment no:03 Date:- ___/____/_____

IMPLEMENTATION OF MACRO PASS-1

3.1 Aim: To implement macro pass-1

3.2 Objectives: 1. To understand macro preprocessor and data structure for macro pass 1

2. To generate required data base for macro pass 2

3.3 Software used / Programming Languages Used: Turbo C/Code block/ C Language

3.4 THEORY:

A macro is unit of specification for program generation through expansion .A macro consists of a
name , a set of formal parameter and body of code. The use of macro name with setoff actual parameter
is reported by same code generated from its body. Thus is called macro expansion. A macro definition is
enclosed in a macro header statement and macro end .State macro definition consists of:

1) Macro prototype statement

2) One or more model statement

3) Macro processor statement

Macro processor:

The macro processor excepts an assembly language program, containing definition and calls
translate it into an assembly language which does not contain any program which does not contain any
macro processor. The program from which output by the macro processor can now be handed over to an
assembler to contain the target language from the program.

Page No. ____ Journal of SP& MCA Lab(SPOS) Expt. No. 3 of 8


For T.E. Year E & TC Engineering
Nashik District Maratha Vidya Prasarak Samaj’s
Karmaveer Adv. Baburao Ganpatrao Thakare College of Engineering, Nashik-13
Department of Electronics & Telecommunication Engineering

Thus macro processor segregates macro expansion from the process of program assembly . It is
economical because it can use any existing assembler. However it is not a efficient as macro assembler
i.e. an assemble that performs macro expansion as well as assembly,

Two pass macro processor –design by listing all task involved in macro expansion:

• Identify macro calls in program.

• Determine the values of formal parameters.

• Maintain the values of expansion time variables declared.

• Organize expansion time control flows.

• Determine the values of sequencing symbol.

• Perform expansion of model statement.

The following four step procedure i.e. followed to arrive at a design in specification for each
table:

• Identify the information necessary to perform the task.

• Design a suitable data structure to record information.

• Determine the processing necessary to obtain the information.

• Determine the processing necessary to perform the task.

In two pass assembler mainly two tasks involved in design of macro processor:

• Processing of macro definition –pass I.

• Processing of macro call pass-II.

Data structure for pass-I:

• Source program as input containing definition and calls of macro.

• Target program as output containing only calls.

• MDT-Macro definition table.

• MNT-Macro name table.

• MNTC-Macro name table counter.

Page No. ____ Journal of SP& MCA Lab(SPOS) Expt. No. 3 of 8


For T.E. Year E & TC Engineering
Nashik District Maratha Vidya Prasarak Samaj’s
Karmaveer Adv. Baburao Ganpatrao Thakare College of Engineering, Nashik-13
Department of Electronics & Telecommunication Engineering

• MDTC-Macro definition table counter.

• ALC-Argument list array.

MDT-MDT index instruction.

MNT-MNT index macro name MDT index.

MNTC and MDTC

Counter to MDT and MNT respectively.

ALA index formal parameter name.

Example:

START

MACRO ABC,& ARG1

MOVER AREG,=’1’

ADD AREG,& ARG

MEND

MACRO XYZ,&ARG1

MOVER BREG,=’20’

SUB BREG,&ARG1

MEND

ABC A

XYZ B

A DC 10

B DC 20

END

Output source program

STRAT

ABC A

XYZ B

Page No. ____ Journal of SP& MCA Lab(SPOS) Expt. No. 3 of 8


For T.E. Year E & TC Engineering
Nashik District Maratha Vidya Prasarak Samaj’s
Karmaveer Adv. Baburao Ganpatrao Thakare College of Engineering, Nashik-13
Department of Electronics & Telecommunication Engineering

A DC 10

B DC 20

END

Data structure:

1)ALA

Index Formal parameter


1. &ARG
2)MNT

Index Macro name MDT index


1 ABC 1
2 XYZ 8

3)MDT

Index Instruction
1 ABC &ARG1
2 MOVER AREG,=’1’
3 ADD AREG ,#1
4 MEND
5 XYZ &ARG
6 MOVER BREG ,=’20’
7 SUD BREG,#2
8 MEND

ALGORITHM FOR PASS1

• SSNTAB-ptr =1

PNTTB –ptr=1

• Process the macro prototype start and form MNT entry

a)Name=macro

b)For each positional parameter

• Enter parameter name in PNTAB(PNTAB etc )

Page No. ____ Journal of SP& MCA Lab(SPOS) Expt. No. 3 of 8


For T.E. Year E & TC Engineering
Nashik District Maratha Vidya Prasarak Samaj’s
Karmaveer Adv. Baburao Ganpatrao Thakare College of Engineering, Nashik-13
Department of Electronics & Telecommunication Engineering

• PNTAB –ptr is PNTAB –ptr+1

• #PP=RPDTAB-ptr

c)RPD-ptr=RPDTAB-ptr

d)For each word parameter

• Enter parameter name and default value in RPDTAB[RPDTAB -ptr]

• Enter parameter name in PNTAB

• RPDTAB-ptr++

• PNTAB-ptr++

• #RP:=#RP++

e)MDTP=MDT-ptr

f)#EV=0

g)While not an MEND statement

• If an LCL statement then

1.Enter expansion time variable in EVTAB

2.#EV=#EV+1

• If a model statement then

1.If the table field contains a sequencing symbol : If symbol is present in SSTAB then

g=SSNTAB-ptr

SSNTAB-ptr=SSNTAB –ptr+1

2.For a parameter generated the specification#W

3.For an expansion variable generate the specification(E,#M)

4.MDT -ptr=MDT -ptr+1

• If the preprocessed statement then

1.If a set statement then search each expansion variable used in the statement in EVNTAB
and generate spec(E,#M)

Page No. ____ Journal of SP& MCA Lab(SPOS) Expt. No. 3 of 8


For T.E. Year E & TC Engineering
Nashik District Maratha Vidya Prasarak Samaj’s
Karmaveer Adv. Baburao Ganpatrao Thakare College of Engineering, Nashik-13
Department of Electronics & Telecommunication Engineering

2.If an AIF or AOG statement then if sequencing symbol used in the statement is present in
SSNTAB else symbol SSNTAB[SSNTAB-ptr]

q=SSNTAB-ptr

SSNTAB-ptr=SSNTAB-ptr+1

3.Record the IC in MDT (MDT-ptr)

4.MDT-ptr=MDT-ptr+1

3)MEND statement

If SSNTAB-ptr=1[i.e. SSNTAB is empty]

Then

SSTP=0

Else

SSTAB-ptr=SSTAB-ptr+SSNTAB-ptr_1

If #SR=0 then RPDTP=0

3.5 CONCLUSION:

Hence we have studied that-

• Macro pass II uses macro definition table, macro name table, and parameter table as input to
produce the target assembly language code.

• It copies the assembly instructions without macro calls as it is while perform macro expansion on
encountering with macro instructions.

Signature of staff

Page No. ____ Journal of SP& MCA Lab(SPOS) Expt. No. 3 of 8


For T.E. Year E & TC Engineering

You might also like