SP Solutions - Adi
SP Solutions - Adi
SP Solutions - Adi
com
www.onlinebu.com
SOUNDARYA EDUCATIONAL TRUST (R)
SOUNDARYA INSTITUTE OF MANAGEMENT & SCIENCE
Soundarya Nagar, Sidedahalli, Hessaraghatta Main Road, Bangalore – 73
5. What is LTORG?
LTORG is a pseudo-op which tells the assembler to place the encountered literals at an
earlier location.
6. Define complier, assembler.
Compiler: Compiler is a program that accepts a source program in high level language
and produces its corresponding object program.
Assembler: Assembler is a program that translates the assembly language program
(Source Code) into machine language program (Object Code).
6. What is sorting?
Sorting is the process of arranging items of the table in some sequence, either in ascending
or descending order.
UNIT - 3
1. What is ALA?(Repeated twice) Explain its format.
ALA is a Argument List Array maintains the details about the parameters. ALA is used
during pass1 and pass2, but the functions are reverse in both the process.
Argument List Array 8 bytes per entry
Index Argument
0 “LOOP1bbb”
1 “DATA1bbb”
2 “DATA2bbb”
3 “DATA3bbb”
Macro Subroutine
Macro can be called only in the program it Subroutine can be called from other
is defined. programs also.
Macro can have maximum 9 parameters. Can have any number of parameters.
[ ] Macro name
________
________ Sequence to be abbreviated
________
UNIT - 4
1. List the functions of a loader.(Repeated four times
Functions of Loader:
I. Allocation: Allocate space in memory for the programs.
II. Linking: Resolve symbolic references between object decks.
III. Relocation: Adjust all address dependent locations, such as address constants, to
correspond to the allocated space.
IV. Loading: physically place the machine instructions and data into memory.
UNIT - 5
1. What is intermediate form?
The process of generating the object code for each construction after determining the
syntactic construction is known as intermediate form.
S Integer
0 1 15
S is Sign bit
Ex: Decimal number +257 is represented as
--------------16 bits ----------------
0 000 0001 0000 0001
b. Long form fixed point numbers: In long form fixed point 32 bits are
allocated, out of this first one bit is used for sign bit(+ or -). The m/c
interprets the contents of this four bytes as an integer. It interprets the first
bit as sign and the remaining 31 bits are as a binary number.
S Integer
0 1 31
S is Sign bit
Ex: Decimal number +257 is represented as
1
0 000 0000 0000 0000 0000 0001 0000 0001
e. Short form floating point numbers: In short form floating point 32 bits
are allocated. Out of this 1 bit is reserved for sign (+ or -). The floating-
point number is divided into exponential and fractional part. This
representation gives a precision of seven decimal places.
0 1 8 31
S C F
Sign Characteristic Fraction
2
f. Long form floating point numbers: In long form floating point 64 bits are
allocated for the floating-point number which contains the exponential and
fractional part. The long length of the fractional part gives up to 17 decimals
of precision, thus eliminating most requirements for double precision
arithmetic.
0 1 8 63
S C F
Sign Characteristic Fraction
g. Logical data: Characters are stored as 8-bit ASCII code each character
occupies 1 byte. The length of character data, varies from 1 to 256 bytes.
1 to 256 bytes
Ch Ch Ch
0 8 15
Character codes(0-7 bits)
2. Draw the general machine structure of IBM 360/370 with a neat diagram.
The structure of CPU for a typical Von Neumann Machine is as follows:
3
The structure above consists of :
1. Instruction Interpreter
2. Location Counter
3. Instruction Register
4. Working Registers
5. General Register
This CPU interfaces with Memory through MAR & MBR. MAR (Memory
Address Register) - contains address of memory location (to be read from or
stored into). MBR (Memory Buffer Register) - contains copy of address
specified by MAR. Memory controller is used to transfer data between MBR
& the memory location specified by MAR. The role of I/O Channels is to input
or output information from memory.
4
4. Explain any 5 pseudo ops, used in an assembly language program.
Pseudo op is an assemble language instruction that specifies an operation of
the assembler.
1. USING: It is a Pseudo-op that indicates to the assembler which general
purpose register to use as a base register and what its contents will be in
order to convert the addresses to base-displacement format. Since no
special register is set aside for addressing, the programmer must inform the
assembler which register to use as a base register and what value it contains
at execution time.
Syntax: USING <contents of base register> <GPR to be used as base
register >
EX: USING *, 5
2. START: It is Pseudo-op that tells the assembler where the beginning of the
program and allow the user to give a name to the program.
Ex: TEST START {TEST is the name of the program}
3. END: It is Pseudo-op that tells the assembler that the last statement of the
program has been reached.
Ex: END
4. EQU: It is Pseudo-op which allows the programmer to define variable. The
operand of the EQU statement can be any constants or valid arithmetic
expressions.
Ex: BASE EQU 15
5
5. DC(Define Constant): DC is declarative Pseudo-op used to create a
memory area to hold a constant value. That is it constructs memory words
containing constants.
Syntax: <Label> DC ‘Constant’
Ex: FOUR DC F’4’
6. DS(Define Storage): DS is declarative Pseudo-op that reserves some
storage for the data and gives them a name.
Syntax: <Label> DS SIZE
Ex: BLOCK DS 100F
7. DROP: It is a Pseudo-op which indicates an unavailable base register.
Syntax: DROP <BR number>
Ex: DROP 15
8. LTORG: It is a Pseudo-op which tells the assembler to place the
encountered literals at an earlier location.
6
Saves time because there is no There is an overhead of transferring
overhead of program control transfer the control to the function and
and return returning back which takes time
Performs only one task i.e insert a Performs two tasks that is transfer of
macro control and transfer of data
Wastage of memory Saves memory
These are loaded into memory at These are loaded into memory at a
different memory locations. i.e based specific address.
on location of calling macro
7
8. Explain the use of literals in assembly language programs using example.
Literals: In many instructions, it is possible to use a shorthand notation in
place of a label for the source memory operand. A literal look like a DC
operand but is preceded by a ‘=’ sign. While using literals, the assembler
creates data areas containing the constants.
Ex:
L 3, TEN
TEN DC F ‘10’
Can be replaced by
L 3, =F’10’
Where =F’10’ is a literal and a data area whose size is 1 full word, containing
the value 10 is created. In the load instruction, the address part points to a full
word containing the value 10.
Literal Table: All the constants that have been specified through literals will
be placed in a table called literal table. Usually it is placed at the end of the
program. LTORG is a pseudo-op which tells the assembler to place the
encountered literals at an earlier location. It is used when the program is very
long. To avoid addressability problems in multimodular programs, LTORG
instruction is coded as the last instruction of each control section in the
program. So, each control section in the program will have its own literal pool
at the end of the module.
9. Differentiate between Pseudo-op and Machine-op with example.
Pseudo-op Please Refer Question no 4.
Machine-op: Machine-op represents to the assembler a machine instruction.
Machine instructions should be included in the program, to load the proper
value into the base register at execution time.
The different machine-op’s are:
1. BALR: It is a branch and link instruction. It is an instruction to the
computer to load a register with the next address and branch to the address
specified in the second field. If the second operand is register o, then
execution proceeds with the next instruction. BALR loads the base register
and is not an executable statement. It is an RR type instruction; whose
length is 2 bytes. Ex: BALR BASE, 0
2. BR: BR is a machine-op indicating branch to the location whose address is
in general register. The calling programs leaves their return address in the
corresponding general register. Ex: BR 14
3. BCT: It indicates branch on count. It is a RX type instruction; whose size
is 4 bytes. Ex: BCT 3, LOOP
8
UNIT – 2
1. Draw an overview flowchart for Pass1 of an assembler.
In general, an assembler must do the following tasks:
1. Generate Instructions:
a. Evaluate the mnemonic of the operations field to produce its machine
code.
b. Evaluate the sub fields- find the value of each symbol, process literals
and assign addresses.
2. Process pseudo ops:
These tasks can be grouped into two passes, associated with each task is one
or more assembler modules. Pass is a sequential scan over the input.
Pass1: Purpose of pass1 is to define symbols and literals.
1. Determine length of machine instructions (MOTGET1)
2. Keep track of location counter (LC)
3. Remember values of symbols until pass2 (STSTO)
4. Process some pseudo-ops, eg, EQU, DS (POTGET1)
5. Remember literals (LITSTO)
9
2. Explain radix sort with suitable example.
Radix exchange sort is a distributive sorting method used when the keys
are represented in binaries. Sorting is accomplished by considering groups
with the same (M) first bits and ordering that group with respect to the (M+1)s
bit. The ordering of a group on a given bit is accomplished by scanning down
from the top of the group for a one bit and up from the bottom for a zero bit,
these two are exchanged and the sort continues.
Ex: 1. sort array with respect to left most bit
1 0
1 0
0 1
1 1
0 1
2. Partition array
0 0
0 0
1
1
1
1
1
1
3. Recursion
Recursively sort top sub array ignoring left most bit.
Recursively sort bottom sub array ignoring left most bit
Sorting is done like partitioning in the quick sort.
The Method is Repeat
Scan top-down to find key starting with 1.
Scan bottom-up to find key starting with 0.
Exchange keys. Until scan indicated cross.
1 0 0 0
1 1 1 0
0 0 0 1
1 1 1 1
0 1 1 1
First exchange Second exchange
10
3. Draw the detailed Pass 2 flowchart of an assembler.
Pass2: Generate code: The purpose of Pass2 is to
1. Process each card and to find the values for its operation code and its
operand field.
2. Structuring the generated code into the appropriate format for later
processing by the loader.
3. To print an assembly listing containing the original source and the
hexadecimal equivalent of the bytes generated.
11
4. Explain databases used by Pass1 and Pass2 of an assembler.
Pass1 Database:
1. Input source program.
2. A Location Counter (LC), used to keep track of each instruction’s location.
3. A table, the Machine-operation Table (MOT), that indicates the symbolic
mnemonic for each instruction and its length.
4. A table, the Pseudo-Operation Table (POT), that indicates the symbol
mnemonic and action to be taken for each pseudo-op in pass1.
5. A table, the Symbol Table(ST), that is used to store label and its
corresponding value.
6. A table, the Literal Table(LT), that is used to store each literal encountered
and its corresponding assigned location.
7. A copy of the input to b used by pass2. This may be stored in a secondary
storage device.
Pass2 Database:
1. Copy of the source program input to pass1.
2. Location Counter(LC).
3. A table, the MOT that indicates for each instruction, symbolic mnemonic,
length, binary machine op code and format.
4. A table, the POT, that indicates for each pseudo-op the symbolic mnemonic
and the action to be taken in pass2.
5. The ST, prepared by pass1, containing each label and its corresponding
value.
6. A table the Base Table(BT), that indicates which registers are currently
specified as base register by USING pseudo-ops and what are specified
contents of these registers.
7. A work-space, INST, that is used to hold each instruction as its various parts
are being assembled together.
8. A work- space, PRINT LINE, used to produce a printed listing.
9. A work-space, PUNCH CARD, used prior to actual outputting for
converting the assembled instructions into the format needed by the loader.
10. An output deck of assembled instructions in the format needed by the
loader.
12
5. Illustrate Binary Search with an example.
Binary search algorithm searches for an item only in an ordered list. It starts
with the middle entry in the table, and compares it with the search element.
This give rise to 3 conditions. They are
1. The search element may be equal to the middle element.
2. The search element may be greater than the middle element.
3. The search element may be less than the middle element.
The next actions taken for each of these out comes is as follows.
1. If the search element is equal to the middle element, the search element is
found.
2. If the search element is greater than the middle element, use the bottom half
of the given table as a new table to search.
3. If the search element is smaller than he middle element, use the top half of
the table as a new table to search.
This method, effectively divides the table in half on each pass, systematically
bracketing the item searched for. The search is terminated with a ’not found’
condition when the length of the last sub table searched is down to 1 and the
item has not been found.
For a binary search to work, it is mandatory for the target array to be sorted.
We shall learn the process of binary search with a pictorial example. The
following is our sorted array and let us assume that we need to search the
location of value 31 using binary search.
Now we compare the value stored at location 4, with the value being
searched, i.e. 31. We find that the value at location 4 is 27, which is not a
13
match. As the value is greater than 27 and we have a sorted array, so we also
know that the target value must be in the upper portion of the array.
We change our low to mid + 1 and find the new mid value again.
low = mid + 1
mid = low + (high - low) / 2
Our new mid is 7 now. We compare the value stored at location 7 with our
target value 31.
The value stored at location 7 is not a match, rather it is more than what we
are looking for. So, the value must be in the lower part from this location.
We compare the value stored at location 5 with our target value. We find
that it is a match.
14
6. List different types of sorting. Explain Interchange sort.
Different types of sorting:
1. Interchange sort.
2. Shell sort.
3. Bucket sort.
4. Radix exchange sort
5. Address calculations sort.
Interchange Sort: It is also known as bubble sort, sinking sort or shifting
sort. It sorts by comparing each adjacent pair of items in a list and swapping
the items if necessary, and repeating the pass through the list until no swap are
done. After each pass at least one item is added to the bottom of the list in a
perfect order. Thus, the name sinking sort, because the elements sinks down
to the proper position.
To arrange a list of items in ascending order using interchange sort, the
first element is compared with the second element. If the first element is
greater then the second, the elements are interchanged Next, the second
element is compared with the third and the process continues until all the
elements of the list are compared. After the end of this (pass1), the largest
element bubbles down to the last position.
In the second pass, the same procedure is followed leaving out the last
element since it is already placed in the correct position. This pass brings the
second largest number to the last but one position. This procedure is repeated
until there are no more elements for comparison.
15
We compare values in each sub-list and swap them (if necessary) in the
original array. After this step, the new array should look like this −
Then, we take interval of 1 and this gap generates two sub-lists - {14, 27, 35,
42}, {19, 10, 33, 44}
We compare and swap the values, if required, in the original array. After this
step, the array should look like this −
Finally, we sort the rest of the array using interval of value 1. Shell sort uses
insertion sort to sort the array.
16
Following is the step-by-step depiction −
We see that it required only four swaps to sort the rest of the array.
17
8. Explain Pass 2 overview of an assembler with flow-chart.
Pass2: Purpose of pass2 is to generate object program.
1. Look up value of symbols(STGET).
2. Generate instructions(MOTGET).
3. Generate data (for DS, DC and literals).
4. Process pseudo ops(POTGET2).
18
9. Draw the detailed Pass1 flowchart of an assembler.
Pass1: Define symbols: The important purpose of pass1 is to
1. Assign a location to each instruction and data and to define pseudo
instructions.
2. To define values for symbols appearing in the label field of the source
program.
19
10. Give format of all five tables used in assembler.
Assembler consists of five tables. MOT, POT, ST, LT and BT.
MOT: Machine Operation Table:
MOT is a fixed table that contains the mnemonic of each instruction. Fixed
table is a table, whose contents are not filled in or altered during the assembly
process.
Format of MOT
-----------------------------6 bytes per entry -----------------------------------
Mnemonic Binary op- Instructions Instruction Not
op-code code (1 byte) Length format used in
(4 bytes) (Hexadecimal) (2bits) (3bits) this
(Characters) (Binary) (Binary) design
(3 bits)
“Abbb” 5A 10 001
“AHbb” 4A 10 001
“ALbb” 5E 10 001
“ALRb” 1E 01 000
“ARbb” 1A 01 000
----- --- --- ---
“MVCb” D2 11 100
---- --- ---- ---
b~ represents the character “blank”
codes: Instruction Length Instruction Format
01= 1 half-words = 2 bytes 000=RR
10= 2 half-words = 4 bytes
001=RX
11= 3 half-words = 6 bytes
010=RS
011=SI
100=SS
20
Format for POT
--------------------8 bytes per entry------------------------------
Pseudo-op Address of routine to process
(5 bytes) pseudo-op
(character) (3-bytes=24 bit address)
“DROPb” P1DROP
“ENDbb” P1END
“EQUbb” P1EQU
“START” P1START
“USING” P1USING
POT is similar for Pass1 and Pass2
LT Format:
---------------------14 bytes per entry-------------------------------
Symbol Value Length Relocation
(8 bytes) (4 bytes) (1 byte) (1 byte)
Character Hexadecimal Hexadecimal Character
F’4’ 4 04 “R”
21
BT: Base Table
BT is a variable table that specifies the base register. It is used only in pass2.
The size of it is 4 bytes per entry.
BT Format:
---------------------4 bytes per entry-------------------------------
Availability Designated relative-address
indicator contents of base register
(1byte) (3 bytes=24 bit address)
Character Hexadecimal
1 “N” ---
2 “N” ---
: :
14 “N” --
15 “Y” 00 00 00
22
UNIT – 3
1. Write an algorithm for Pass1 processing macro definitions.
Pass 1 Algorithm:
-by-line scan over its input.
as MNTC=1.
23
Advantages of incorporating the macro processor into pass1 of assembler:
1.Many functions do not have to be implemented twice.
2.There is less over head during processing.
3.Functions are combined and it is not necessary to create intermediate files as
output from the macro processor and input to the assembler.
4.More flexibility is available to the programmer in that he/she may use all the
features of the assembler in conjunction with macros.
Macro Instruction Arguments : The macro which we have seen before lacks
flexibility, because all of the calls to any given macro will be replaced by
identical blocks. There is no way for a specific macro call to modify the coding
that replace it.
In order to overcome this problem, we use macro instruction in macro calls.
The corresponding macro dummy arguments call appear is macro definitions.
Two methods of arguments:
1.Positional Arguments: These are matched with the dummy arguments
Ex: INCR A,B,C
2.Keyword Arguments: Allows reference to dummy arguments by name as
well as by position.
24
4. Explain macro definitions with an example.
Macro instruction definition defines a name for sequence of operations.
25
5. Explain simple one pass macro processor.
A Single pass Algorithms for Macro Definitions within Macro.
case of macro definition within the macro, the inner macro is defined only
after the outer macro has been called.
for any use of inner macro, we have to repeat both macro definition
and the macro call passes.
order to avoid this repetition we can reduce all macro processing to single
pass.
macro definitions must be processed before calls because macros must
be defined to the processor before it can expand calls.
Additional Data Structure Included
MDI-Macro Definition Input indicator: It keep track of macrocalls.
MDI=“ON” while expanding a macro call otherwise MDI=“OFF”.
MDLC-Macro Definition Level Counter: It is used to keep track of macro
definitions. It is a counter for MACRO and MEND pseudo-ops, when MACRO
pseudo-op is encountered, MDLC is incremented by one and is decremented
by one when MEND pseudo-op is encountered.
MDT format:
Index Card
1 DEFINE &SUB
2 MACRO
3 #1 &Y
4 CNOP 0,4
5 BAL 1,*+8
6 DC A(&Y)
7 L 15=V(#1)
8 BALR 14.15
9 MEND
10 MEND
26
MNT Format:
Index Name MDT Index
1 DEFINE 1
27
7. Explain macro instructions defining macros with an example.
definition, which itself is a sequence of instruction, can be abbreviated
by using macro.
is important that inner macro is not defined until the outer macro is called.
user can call the above macro with the statement DEFINE MACRO
ADD1
this call is executed then the macro ADD1 will be defined. So after the
above call user can call the ADD1 macro as following:
ADD1DATA1
The microprocessor will generate the sequence as
L1,DATA1
A1,=F’10’
ST1,DATA1
8. Give the database specifications for Pass1 and Pass2 of macro processor.
Pass1–Databases:
1.The input macro source deck.
2.The output macro source deck copy for pass2.
3.MDT (Macro Definition Table) to store the body of the macro definitions.
4.MNT(Macro Name Table) to store the names of defined macros.
5.MDTC(Macro Definition Table Counter) to indicate the next available entry
in MDT.
6.MNTC(Macro Name Table Counter) to indicate the next available entry in
MNT.
7.ALA(Argument List Array) to substitute index markers for dummy
arguments before storing a macro definition.
28
Pass 2 –Databases:
1.Copy of the input macro source deck.
2.Output expanded source deck to be used as input to the assembler.
3.MDT created by Pass1.
4.MNT created by Pass1.
5.MDTP(Macro Definition Table Pointer) used to indicated the next line of text
to be used during macro expansion.
6.ALA to substitute macro call arguments for the index markers in the stored
macro definition.
Save the definitions: The processor must store the macro-definitions which
will be needed at the time of expansion of calls.
Recognize the Macro call: The processor must recognize macro calls that
appear as operation mnemonics.
Expand calls and substitute arguments: The macro call is replaced by the
macro definition. The dummy arguments are replaced by the actual data.
10. Explain the terms macro definition, macro call, macro expansion with syntax
and example.
Macro definition Refer Question no 4
Macro Call
Once the macro has been defined, the use of macro name as an operation
mnemonic in an assembly program is equivalent to the corresponding
instruction sequence. i.e., in the program, the repeated instruction sequence are
written with the macro name. This is called as macro call or macro
invocation.
29
Ex:
Macro Expansion
Whenever there is a macro call the macro processor substitutes the macro
definition in the place of the macro call. This is called as Macro Expansion.
•The macro definition itself appear in the expanded source code.
•The definition is saved by the microprocessor.
30
UNIT – 4
1. Explain the design of Absolute Loader with a neat diagram.
Absolute Loader:
In this scheme the object program is placed in secondary devices. The loader
only accepts the machine language text & places into core at the location
prescribed by the assembler.
Disadvantage is that the programmer must specify the load address in the
program & also if there are multiple subroutines, the programmer must
remember the address of each & use that in other subroutines to perform
subroutine linkages.
31
2. Write a note on direct linking loader.
• It is a general relocatable loader, and is perhaps the most popular loading
scheme presently used.
• It has advantage of allowing the programmer multiple procedure segments
and multiple data segments.
• Other segments provide flexible intersegment referencing and accessing
ability, while translation of the programs.
• The assemble must give the loader the following information with each
procedure or data segment:
1. The length of object code segment.
2. A list of all the external symbol (could be used by other segment).
3. A list of all the external symbol (used by the segment)
4. Information about address constants.
5. The machine code translation of the source program.
32
The assembler produces four types of cards in the object deck
• External Symbol Dictionary(ESD): It contains information about all
symbols that are defined in the program but referred somewhere.
• The Text Cards(TXT): It contains the actual object code translated version
of the source program.
• The Relocation and Linkage Directory(RLD): Contain information about
locations in the program whose contents depend on the address at which the
program is placed.
• The END card: Indicates the end of the object deck and specifies the
starting address for execution.
33
4. Explain compile-and-go loader with a diagram.
Method of performing the loader functions is to have the assembler run
in one part of memory and place the assembled machine instructions and data,
as they are assembled, directly into their assigned memory locations. When
the assembly is completed, the assembler causes a transfer to the starting
instruction of the program. This is simple solution, involving no extra
procedures. It is used by the complier and several other language processors.
It is relatively easy to implement. The assembler simply places the code
into core, and the “loader” consists of one instruction that transfers to the
starting instruction of the newly assembled program is called “compile-and-
go or assemble-and-go”.
Advantages:
1. It is relatively easy to implement.
2. It is simple and easy to follow.
Disadvantages:
1. A portion of the memory is wasted.
2. It is necessary to retranslate the program every time.
3. It is very difficult to handle multiple segments, specifically when they are in
different languages, so it is very difficult to produce modular programs.
34
5. Explain the databases used by Pass1 and Pass2 of a direct linking loader.
Pass 1 Data Bases:
1. Input object decks.
2. A parameter, the Initial Program Load Address(IPLA) supplied by the
programmer or OS, that specifies the address to load the first segment.
3. A Program Load Address (PLA) counter, used to keep track of each
segment’s assigned location.
4. A table, the Global External Symbol Table(GEST), that is used to store each
external symbol and its corresponding assigned core address.
5. A copy of the input to be used later by pass 2. this may be stored on an
auxiliary storage device, such as magnetic tape, disk, drum or the original
object decks may be reread by the loader a second time for pass 2.
6. A printed listing, the load map, that specifies each external symbol and its
assigned value.
Pass 2 Data Bases:
1. Copy of object programs inputted to pass 1.
2. The Initial Program Load Address parameter (IPLA).
3. The Program Load Address Counter(PLA).
4. The Global External Symbol Table(GEST), prepared by pass 1, containing
each external symbol and its corresponding absolute address value.
5. An array, the Local External Symbol Array(LESA), which is used to
establish a correspondence between the ESD ID numbers, used on ESD and
RLD cards, and the corresponding external symbol’s absolute address
value.
6. Explain dynamic loading.
In each of the loader schemes we have assumed that all of the subroutines
needed are loaded into the memory at the same time. If the total amount of
memory required by all these subroutines exceeds the amount available, then
there is trouble. Then we use dynamic loading schemes to solve this problem.
Dynamic loading is also called load-on-call. This is done to save
memory. If all the subroutines are loaded simultaneously, a lot of space is taken
up. But only one is used at a time. So, here only the required subroutines are
loaded. To identify the call sequence, we use a data structure called OVERLAY
STRUCTURE. It defines mutually exclusive subroutines. So, only the ones
needed are loaded and a lot of memory is saved. In order for the overlay to
work, it is necessary for the module loader to load the various subroutines as
they are needed.
35
7. Describe four types of cards used in direct linking loader.
Four types of cards used in direct linking loader:
1. External Symbol Dictionary(ESD): It contains information necessary to
build the external symbol dictionary or symbol table. External symbols are
symbols that can be referred beyond the subroutine level. The normal labels
in the source program are used only by the assembler and information about
them if not included in the object deck.
There are 3 types of external symbol:
1. Segment Definition (SD) name on START or CSECT card.
2. Local Definition(LD) specified on ENTRY card.
3. External Reference(ER) specified on EXTRN card.
2. The Text Cards(TXT): It contains the block of data and the relative
address at which the data is to be placed. Once the loader has decided where
to load the program, it merely adds the Program Load Address(PLA) to the
relative address and moves the data into the resulting location. The data on
the TXT card may be instructions, nonrelocated data, or initial values of
address constants.
3. The Relocation and Linkage Directory(RLD): Contain information about
1. The location and length of each address constants that needs to be
changed for relocation or linking.
2. The external symbol by which the address constant should be modified.
3. The operation to be performed.
4. The END card: Indicates the end of the object deck and specifies the start
of execution point for entire program. This address is recorded on the END
36
card. There is a final card required to specify the end of a collection of
object decks. The 360 loaders usually use either a Loader Terminate(LDT)
or End of File (EOF).
Advantages:
• Relocation bits are used to solve the problem of relocation , transfer vector is
used to solve the problem of linking & program length information to solve
allocation.
Disadvantages:
1. Not suited for loading external data. Transfer vector increases the size.
2. Does not facilitate access to data segments that can be shared
3. It is necessary to allocate, relocate, link and load all the subroutines each time,
in order to execute a program.
37
9. Define binder. What are the classes of binders? Explain.
Binders: It is a program similar to direct-linking loader in binding subroutine
together, but rather than placing the relocated and linked text directory into
memory, it outputs the text as a file or card deck. This output file is in a format
ready to be loaded and typically called a load module.
The binder essentially performs the functions of allocation, relocation
and linking the module loader merely the function of loading.
There are two major classes of binders:
1. Core Image Builder: the simplest type produces a load module that looks
very much like a single absolute loader deck. This means that the specific
core allocation of the program is performed at the time that the subroutines
are bound together. Since this kind of module looks like an actual “snapshot
of image” of a section of core, it is called core image module and the
corresponding binder is called a core image builder.
2. Linkage Editor: A more sophisticated binder, called a linkage editor, can
keep track of the relocation information so that the resulting load module,
as an ensemble, can be further relocated and thereby loaded anywhere in
core. In this case the module loader must perform additional allocation and
relocation s=as well as loading, but it does not have to worry about the
complex problems of linking.
10. Explain the use of EXTERN and ENTRY statements.
ENTRY and EXTRN statements Consider an application program AP
consisting of a set of programs unit’s SP = {P (i)}. A program unit P (i)
interacts with another program unit P (j) using addresses of P (j)’s instructions
and data in its own instructions. To realize such interactions, P (j) and P (i)
must contain public definitions and external references as defined in the
following.
Public definition: a symbol pub_symb defined in a program unit which may
be referenced in other program units. This is denoted with the keyword
ENTRY and in the e.g. it is TOTAL.
External reference: a reference to a symbol ext_symb which is not defined in
the program unit containing the reference. This is denoted with the keyword
EXTRN and in the e.g. it is MAX and ALPHA.
These are collectively called subroutine linkages. They link a subroutine which
is defined in another program.
EXTRN: EXTRN followed by a set of symbols indicates that they are
definedin other programs, but referred in the present program.
ENTRY: It indicates that symbols that are defined in the present program are
referred in other programs.
38
UNIT – 5
1. What are the functions of analysis and synthesis phases of compiler.
Analysis phase reads the source program and splits it into multiple tokens and
constructs the intermediate representation of the source program.
And also checks and indicates the syntax and semantic errors of a source
program.
It collects information about the source program and prepares the symbol
table. Symbol table will be used all over the compilation process.
This is also called as the front end of a compiler.
Synthesis phase: It will get the analysis phase input (intermediate
representation and symbol table) and produces the targeted machine level
code.
This is also called as the back end of a compiler.
39
2. Write a note on assembly phase of compiler.
The process of generating the actual code is known as Assembly phase.
1. The code generation phase is producing assembly language, the compiler is
generating references to actual code in place of literals and variables
assigned by a storage allocation routine.
2. The assembly phase must resolve the label references in the object program,
format the appropriate information for the loader. If the code generator
simply generates symbolic machine names instructions and labels, the
assembly phase must
Resolve label references.
Generate binary machine instruction.
Convert literals.
Calculate addresses.
Generate storage.
3. Explain intermediate form of compiler.
The process of generating the object code for each construction after
determining the syntactic construction is known as Intermediate form.
Advantages of Intermediate form:
This facilitates optimization of object code.
It allows logical separation between the machine-independent phase and
machine-dependent phase.
The Intermediate form depends on syntactic construct such as:
1. Arithmetic statements.
2. Non-Arithmetic statements.
3. Non-Executable statements.
40
Use algebra rules to construct the tree:
1. Highest priority is given to the expression in the ().
2. * and / are having second priority.
3. + and – are having third priority.
4. If the sequence of the operators is same, then start solving from left to right.
Consider the ex. A= B+C
Then parse tree is
Non-Arithmetic statements: The statements DO, IF, GOTO etc. can all
replaced by a sequentially ordering of individual matrix entries.
Matrix
Non-Executable statements:
1. It declares the compiler information that clarifies the referencing or
allocation of variables and associated storage.
2. There is no intermediate form of the statement, but the information
contained in a non executable statement is entered into tables, to be used by
other parts of the compiler.
Ex: DECLARE (COST, RATE, START, FINISH) FIXED BINARY (31)
STATIC;
Fixed binary datatype, 31 bits length and static storage.
41
4. Discuss briefly about lexical phase of compiler.
Lexical Analysis: Recognition of basic elements or tokens and uniform
symbols.
The three tasks of the lexical phase are:
1. To parse the source program into the basic elements of the language.
2. To build a literal table and an identifier table.
3. To build a uniform symbol table.
Databases: It manipulates 5 databases.
1. Source Program: Original form of the program; appears to the compiler as
a string of character.
2. Terminal Table: It is a permanent table. Each entry consists of Terminal
symbol (arithmetic operators, keywords etc.,) an Indication of its
classification (operator, break character) and Precedence (used in later
phases).
SYMBOL INDICATOR PRECEDENCE
3. Literal Table: It is created by lexical analysis to describe all literals used
in the source program.
There is one entry for each literal consisting of a value, a number of
attributes, an address denoting the location of the literal at execution time,
and other information.
42
5. Explain the structure of a compiler with a neat diagram.
Structure of Compiler:
In analysing the compilation process, there are 7 distinct logical problems as
follows:
1. Lexical Analysis: Recognition of basic elements or tokens and uniform
symbols.
2. Syntax Analysis: Recognition of basic Syntactic construct through
reductions.
3. Interpretation: Definition of exact meaning, creation of matrix and tables.
4. Machine Independent Optimization: Creation of more optimal matrix.
5. Storage Assignment: Modification of identifier and literal tables.
6. Code Generation: A macro processor is used to produce more optimal
assembly code.
7. Assembly and Output: Resolving symbolic addresses and generating the
machine language.
Phase 1 to 4 is machine-independent and language dependent.
Phase 5 to 7 is machine-dependent and language independent.
43
The following are the database used by the compiler.
Source code: The user program is the source code.
Uniform symbol table: It consists of full or partial list of the tokens.
Terminal table: It lists all keywords and special symbols.
Identifier table: It contains all variable in the program.
Literal table: It consists of constants in the program.
Reductions: It is a permanent table of decision rules in the form of pattern
for matching with the uniform symbol table.
Matrix: It is created by the intermediate form of the program which is in
turn created by the action routines.
Code productions: It is a permanent table of definitions. There is one entry
defining code for each matrix operator.
Assembly code: Assembly language version of the program which is
created by the code generation phase and is input to the assembly phase.
Relocatable object code: The final output of the assembly phase, ready to
be used as input to loader.
44
7. Explain Machine independent optimisation.
Removing or deleting the duplicate entries in the matrix and modifying all
references to the deleted entries is one type of machine independent
optimization.
Other machine independent optimization are:
1. Compile time computation of operations, both of whose operands are
constants.
2. Movement of computations involving non varying operands out of loops.
3. Use of the properties of Boolean expression to minimize their computation.
Ex: When a subexpression occurs in the same statement more than once, the
duplicate entries can be deleted in the matrix and can be modified as shown in
the table.
45
Matrix with common Matrix after elimination of
subexpression common subexpression
1 - START FINISH 1 - START FINISH
2 * RATE M1 2 * RATE M1
3 * 2 RATE 3 * 2 RATE
4 - START FINISH 4
5 - M4 100 5 - M4 100
6 - M3 M5 6 - M3 M5
7 - M2 M6 7 - M2 M6
8 = COST M7 8 = COST M7
Elimination of common subexpression
*****
46