Unit-Ii Sab
Unit-Ii Sab
MACRO PROCESSOR
AND COMPILERS
INTRODUCTION
: : 2, data 2
: : A
:
LOOP2 INCR data3, data2, data1 3, data 3
: :
: :
data1 DC F ‘5’ LOOP 2 A 1, data3
DC F ‘6’ data1 DCAF ‘5’
data2 DC F ‘7’ data2 DC F ‘6’
2, data2
data3 DC F ‘7’
A
data3
Two ways of specifying
arguments to a macro call
⦿ A) Positional argument
Argument are matched with
dummy arguments according to
order in which they appear.
⦿ INCR A,B,C
⦿ „A‟ replaces first dummy
argument
⦿ „B‟ replaces second dummy
argument
⦿ „C‟ replaces third dummy
⦿ B) keyword arguments
⦿ This allows reference to
dummy arguments by name
as well as by position.
⦿ e.g.
⦿ INCR &arg1 = A,&arg3 = C,
&arg2 =‟B‟
⦿ e.g.
⦿ INCR &arg1 = &arg2 = A,
&arg2 =‟C‟
Conditional macro
expansion
⦿ This allows conditional selection of machine
instructions that appear in expansion of
macro call.
⦿ The macro processor pseudo op-codes AIF
and
AGO help to do conditional macro expansion.
⦿ AIF is conditional branch pseudo op, it
performs arithmetic test and branch only if
condition is true.
⦿ AGO is unconditional pseudo op or it is like
go to
statement.
⦿ Both statements specify a label appearing
in some other instruction within macro
definition.
⦿ These are macro processor directives and
they do not appear in expanded source
Source Program Expanded Program
:
MACRO
& arg0 INCR & count, & arg1, & arg 2, & arg3
& arg0 A 1, &arg1
AIF (& Count
EQ.1). FINAL LOOP1 A 1, data1
A 2,& arg2 A
AIF (&count EQ 2).
FINAL 2, data2
.FINAL MEND
A 3, &arg3 A
:
LOOP1 INCR 3, data1, data2, data3 1, data3
3, data3
: A
: 2, data2
: ::
LOOP2 INCR 2, data3, data2 :
LOOP2 A
: LOOP3 A 1, data1
LOOP3 INCR 1, data1 :
: data1 DC ‘5’
data1 DC ‘5’ data2 DC ‘6’
DC ‘6’ data3 DC ‘7’
data2 DC ‘7’ :
Macro-calls within macro
⦿ Macros are abbreviations of
instruction sequence. Such
abbreviations are also present
within other macro definition.
Macro-calls within macro
Source Code Expanded code (level 1) Expanded code (level 2)
:
:
MACRO
A
DD 1,
&arg
L
MEND1,
&arg
MACRO
ADDSA&arg1, &arg2, arg3
ADD11,&arg1
= F ‘10’&arg2
ADD1
ADD1ST &arg3
MEND 1,
Expansion of
&arg
: ADDS
: :
ADDS data1, ADD1 : data
data2, data3 1
: ADD1 data
data 1: DC F‘5’ 2
data 2 DC F‘6’ ADD1 data
data 3 DC F‘7’ 3
END :
: DC F ‘5’
: DC F ‘6’
: DC F ‘7’
data
data
Source Code Expanded code (level 1) Expanded code (level 2)
:
:
MACRO
A
DD 1,
&arg
L
MEND1,
&arg
MACRO
ADDSA&arg1, &arg2, arg3
ADD11,&arg1 Expansion of
= F ‘10’&arg2
ADD1 ADD1
ADD1ST &arg3 L 1, data 1
MEND 1, A 1, = F
Expansion of
&arg „10‟
: ADDS
: : ST 1, data
ADDS data1, ADD1 : data 1
L 1, data 2
data2, data3 1 A 1, = F
: ADD1 data „10‟
2 ST 1, data
data 1: DC F‘5’
ADD1 data 2
L 1, data 3
data 2 DC F‘6’ A 1, = F
data 3 DC F‘7’ 3
„10‟
END :
ST 1, data
: DC F ‘5’
3
: DC F ‘6’
data1 DC F‘5’
: DC F ‘7’
DC F‘6’
data
data2 DC F‘7’
data
MACRO INSRTUCTION
MDTC MDTC+1
MDTC MDTC+1
Algorithm for Pass – 2
⦿ This algorithm reads one line of i/p prog. 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 defns 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
MDTP MDTP + 1
MACROS PROCEDURE
1
The corresponding machine 1 The Corresponding m/c code
code is
is written every time a macro written only once in memory
is called in a program.
2
2
Program takes up more Program takes up
memory space. comparatively less memory
3
3 space.
No transfer of program counter.
Transferring of program counter is
4
4
No overhead of using stack required.
for transferring control. Overhead of using stack
5
5
Execution is fast for transferring control.
6
6
Execution is comparatively slow.
Assembly time is more.
Assembly time is comparatively
7
7
less.
More advantageous to the
More advantageous to the
programs when repeated group of
programs when repeated group of
instruction is too short.
instructions is quite large.
INTRODUCTION TO COMPILERS
• What is Compiler
• Brief History of compiler
• Task of compiler
• Phases of compiler source code
Compiler
Compiler
• Is a program that translates one
language to another
• Takes as input a source program
typically written in a high-level language
Brief History of compiler
Loader
A
B B
Data Base
Program Loaded in
memory ready for
Execution
Loader
Schemes
⦿ Compile-and-Go loader
⦿ General Loader
Scheme
⦿ Absolute Loading
scheme
⦿ Subroutine Linkages
⦿ Relocating Loaders
⦿ Direct Linking Loaders
Compile-and-Go
Loader
Source program
deck
⦿ In this scheme assembler run in
one part of memory and place
object instructions & data, as
they are assembled, directly into
their assigned memory location.
⦿ When assembly is completed,
assembler causes a transfer
to the starting instruction of
the program
⦿ Advantages:-
⦿ It is relatively easy to implement.
Assembler simply places code into core
and loader transfer control to starting
instruction of newly assembled
⦿ program.
⦿ Disadvantages:-
⦿ i) A portion of memory is always
occupied by assembler. That portion
is unavailable to any other object
program.
⦿ ii) User‟s program have to be
reassemble every time it is run.
⦿ iii) If source program contains sub
routine written in different languages,
then different assemblers have to be
stored in memory ( i.e. again wastage
of memory).
General Loading
Scheme
General Loader Scheme
⦿ In this scheme the output of assembler is
saved and loaded whenever code is to be
executed.
⦿ Disadvantage:-
Addition of a new program „Loader‟ into system.
Absolute
Loader
10
0
MAIN 10
0
24
8 Absolute MAIN
Loader 24
40 8
0 SQRT
47 40
SQRT
8 0
Object
Deck 478
Main
Memory
Absolute Loaders:-
⦿ The simplest type of loader
scheme which fits to the general
model is called as absolute
loader.
⦿ Assembler produces object
code, which is stored on
secondary storage ( instead of
directly loaded into main memory
like in compile -&-go).
⦿ Loader in turn accepts this object
code, places it into core at
prescribed place by assembler for
Advantages:-
⦿ This scheme makes more memory available
to the
user, an assembler is not in memory at load
time.
⦿ Simple to implement.
Disadvantages:-
⦿ Programmer must specify to the assembler,
the address of memory location where
program is to be loaded.
⦿ When program contains more than one
subroutines, then programmer must
remember the address of each and have to
user it explicitly in other subroutines to
perform subroutine linkages.
⦿ Programmer must be careful not to assign
same or
Thus in absolute loader
scheme four loader functions
are performed by
⦿ - by
Allocation programmer
⦿ Linking
Relocation- -by
by
⦿
assembler programmer
Loading
⦿
- by loader
Subroutine linkage
⦿ The problem is:: A MAIN program A wishes to
transfer to sub-program B . However the
assembler does not know this symbol and
declare it as an undefined symbol (error) unless
a special mechanism has been provided.
⦿ This mechanism has been implemented with a
direct-linking or a relocating loader.
⦿ The assembler pseudo-op EXTRN followed by a
list of symbols indicates that these symbols are
defined in another programs.
⦿ Correspondingly if a symbol is defined in one
program and referenced in others, we insert it
into a symbol list following the pseudo-op
ENTRY.
⦿ The assembler will also inform the loader that
these symbols may be referenced by other
programs.
Subroutine linkage(Cont…1)
⦿ Consider the following
MAI START
example::
N EXTRN SUBROUT
L 15, = A(SUBROUT)
BALR 14,15 // reg 14 is return addr of
caller.
END
The subroutine can be defined at other
SUBROUT
location asSTART
::
USING *,1
5
BR 14
EN
Relocating loaders
⦿ To avoid possible reassembling of
all subroutines when a single
subroutine is changed, and to
perform the task of allocation and
linking for programmer, relocating
loaders are developed.
⦿ In this scheme, assembler
assembles each procedure
segment independently and
passes on the text and information
after relocation & inter
segment references to the loader.
⦿ Example:: BSS(Binary Symbolic
Subroutines) loader used in IBM 7094,
IBM 1130, etc.
⦿ The o/p of a relocating assembler
using a BSS scheme is the object
program & information about all
programs it references.
⦿ It also provides the relocating
information that needs to be
changed if it is placed in an
arbitrary place in core.
⦿ BSS loader scheme is used on
computers with a fixed length direct
address instruction format.
5.RELOCATING LOADER(Cont…1)
SSOOUURRCCEE PPRROOGGRRAAMM RREELL.. RREELLOOCCAATTO
I ONN OOBBJJEECCTT
AADDDDRR CCOODDEE
MAIN START
EXTRN SQRT 0 00 „SQRT‟
EEXXTTRRN EERRRR 44 0000 „„EERRRRbb‟‟
N
SSTT 1144, 88 0011 SSTT
SSAAVVEE 1144,3366
L 1,=F „9‟ 12 01 L 1,40
BAL 14,SQRT 16 01 BAL 14,0
C 1, = F „3‟ 20 01 C 1,44
BNE ERR 24 01 BC
7,4
L 14, SAVE 28 01 L 14,36
BR 14 32 0 BCR 15,14
⦿ Drawbacks ::
1) The transfer vector linkage is only useful
for transfers & is not well situated for
loading or storing external data(data
located in another procedure segments).
2) The transfer vector increases the size of
the object program in memory.
5
6. DIRECT-LINKING LOADER(cont…1)
END
RLD
TXT
ESD
FIG: - O B J E C T D E S K FO R A D IREC T LINKING LOADER
⦿ESD – External Symbol dictionary.
⦿ TXT – Text (contains actual assembled
program).
⦿ RLD - Relocation & Linkage Directory. –
contains information about those locations
in the program whose contents depends on
⦿ Location
the addressof ateach constant
which the needs to is
program
that
placed. changed
These due to are:: be
information
relocation.
⦿ By what it has to be changed.
⦿ The operation to be
DIRECT-LINKING LOADER(cont…2)
⦿ ADVATAGES::
1)It allows the programmer multiple
procedure & data segments.
2)Complete freedom for the programmer to
refer the data in other segments.
3)Provides flexibility in
intersegment referencing &
accessing ability.
4)Allows independent translations of the
programs.
⦿ DISADVATAGES::
5)It is necessary to allocate, relocate, link &
load all of the subroutines each time in
3)order to execute
Although loader ais program.
smaller than
These
6)it loading
occupies somearememory
Time-consuming.
assembler,
space.
OT H E R LOADING S C H E M E S
⦿ These includes Binders, linking loaders,
Overlays & Dynamic loaders.
⦿ Binders:: - A Binder is a program that
performs the same functions as that of a
direct-linking loader in binding subroutines
together, but rather than placing the
relocated & linked text directly into memory,
it outputs the text as a file or a card deck.
⦿ This o/p file to be loaded is called as “load-
module”.
⦿ The functions of binders are ::
Allocation, Relocation, Linking & Loading.
⦿ There are 2 major classes of Binders::
⚫ Core – image module.(
6 fast & simple)
Dynamic Loading
overlays
⦿ Each of the previous loader
schemes assume that all of the
subroutines are loaded into core at
the same time. It the total
amount of memory available is less
than memory required by all
needed subroutines, then there
will be trouble.
Solution to above problem
can be-
⦿ Some hardware techniques like
paging and segmentation are used
to solve this problem
⦿ There is loading scheme called as
dynamic loading which is also
available to solve above problem.
⦿ Usually different subroutines are
needed at different times. E.g.
PASS1 & PASS2 of assembler are
mutually exclusive.
Both can be loaded one after
another, need not to be loaded at
the same time.
⦿ By determining which
subroutines call another, which
are exclusive , we can produce
an overlay structure, that will