You are on page 1of 43

DHANALAKSHMI SRINIVASAN COLLEGE OF ENGINEERING (An ISO 9001:2008 Certified Institution) Coimbatore-641 105

B.E./B.Tech. DEGREE EXAMINATION

V Semester

Information Technology

CS 2304- SYSTEM SOFTWARE

QUESTION & ANSWER BANK

2013-14

V Sem IT Unit-3 PART A (2 Marks) 1. What are functions of loader? Functions of loader are: Allocation Linking Relocation Loading

CS 2304 System Software

Nov/Dec-2010

2. Define dynamic linking.

Nov/Dec-2010,May/June 2013

Dynamic linking is defined as a process of postponing linking and loading of external reference until execution is called dynamic linking.

3. What is meant by dynamic loading?

May/June-2011

If the program to be executed is larger in size than the memory in the system, then all of its modules cant be together loaded into the main memory. So the program is divided into segments or pages. Only needed segments or pages will alone be linked into the main memory. After the execution of these segments or pages, another set of segments or pages will be linked or loaded into the main memory. This is called dynamic loading.

4. Differentiate linkage editors from linking loaders S.No 1. Linkage Editors Linking Loaders

May/June-2011

The linkage editor produces a linked The linking loader performs all the version or load module of the program. linking and relocation operations

including automatic library search. 2. The relocating loader loads the load There is no need of relocating loader module into the memory.

2|P a ge

V Sem IT 5. What are the functions of loader and linker? Functions of loader are: Allocation Linking Relocation Loading Functions of Linker are: Translation Linking Loading

CS 2304 System Software Nov/Dec-2011

6. Define relocation.

Nov/Dec-2011

Relocation is the process of updating the addresses of a program. It is necessary that such a modification should help to execute the program from designed area of the memory.

7. What is a bootstrap loader?

May/June-2012

The bootstrap loader is a small program in ROM. Its task is to load the necessary portion of operating system in the main memory.

8. What are the advantages of dynamic linking? The overhead on the loader is reduced. The system can be reconfigured.

May/June-2012

9. What do you mean by linking?

Nov/Dec-2012

Linking is a process of resolving external references between object modules. In the linking process ready to execute program is prepared.

10. Define absolute loader.

Nov/Dec-2012

Absolute loader is a kind of loader in which relocated object files are created, and then the loader accepts these files and places them at specified locations in the memory.

3|P a ge

V Sem IT 11. Give the algorithm for absolute loader. Algorithm for absolute loader: Begin For each program segment do Begin

CS 2304 System Software May/June-2013

Read the first line from object module to obtain information about memory location. The starting address says S in corresponding object module is the memory location where executable code is to be placed. Hence Memory_location = S Line_counter = 1; as it is first line While (! End of file) For the current object code do Begin 1. Read next line 2. Write line into location S 3. S= S+1 4. Line_counter = Line_counter+1 end end end

4|P a ge

V Sem IT PART B (16 Marks) 1. Explain the following (a) Assemble-and-go loader. (8 Marks) (b) Absolute loader. (8 Marks) a) Assemble-and-go loader

CS 2304 System Software

Nov/Dec-2010

In this type of loader, the instruction is read line by line, its machine code is obtained and it is directly put in the main memory at some known address. That means the assembler runs in one part of memory and the assembled machine instructions and data is directly put into their assigned memory locations. After completion of assembly process loader contains the instruction using which the location counter is set to the start of the newly assembled program. The example is WATFOR-77; its a FORTRAN compiler which uses such load and go scheme. This loading scheme is also called as compile and go loader.

User Program

Assemble and go Loader

Program for execution

Assembler

Advantage This type of loader is simple to implement. Because assembler is placed at one part of the memory and loader simply loads assembled machine instructions into the memory.

5|P a ge

V Sem IT Disadvantages

CS 2304 System Software

The Assemble-and-go loader is a combination of assembler and loader activities, this combination program occupies large block It cannot handle multiple source programs or multiple programs written in different languages. This is because assembler can translate one source language to other target language. For a programmer it is very difficult to make an orderly modulator program and also it becomes difficult to maintain such program, and the Assemble and go loader cannot handle such programs. The execution time will be more in this loader as every time program is assembled and then executed.

(b) Absolute loader Absolute loader is a kind of loader in which relocated object files are created, loader accepts these files and places them at specified location in the memory. This type of loader is called absolute because no relocation information is needed; rather it is obtained from the programmer or assembler. The starting address of every module is known to the programmer, this corresponding starting address is stored in the object file, then task of loader becomes very simple and that is to simply place the executable form of the machine instructions at the locations mentioned in the object file. In this the programmer should take care of two things: First thing is specification of starting address of each module to be used. If some modification is done in some module then the length of that module may vary. These causes a change in the starting address of immediate next modules, then the programmer make necessary changes in the starting addresses of respective modules. Second thing is, while branching from one segment to another the absolute starting address of respective module is to be known by the programmer so that such address can be specified at respective JMP instruction.

6|P a ge

V Sem IT Algorithm for absolute loader: Input: Object codes and starting address of program segments

CS 2304 System Software

Output: An executable code for corresponding source program. This executable code is to be placed in the main memory. Method: Begin For each program segment do Begin Read the first line from object module to obtain information about memory location. The starting address says S in corresponding object module is the memory location where executable code is to be placed. Hence Memory_location = S Line_counter = 1; as it is first line While (! End of file) For the current object code do Begin 1. Read next line 2. 3. 4. end end end Write line into location S S= S+1 Line_counter = Line_counter+1

2. Explain the following: (a) Relocating loader. (8 Marks) (b) Overlays. (8 Marks) (a) Relocating loader The relocating loader cannot have the direct access to the source code. And to place the object code in the memory there are two situations: Either the address of the object code could be absolute which then can be directly placed at the specified location or the address can be relative.
7|P a ge

Nov/Dec-2010

V Sem IT

CS 2304 System Software The assembler should give the following information to the loader The length of the object code segment The list of all the symbols which are not defined in the current segment but can be used in the current segment. The list of all the symbols which are defined in the current segment but can be referred by the other segments. The lists of symbols which are not defined in the current segment but can be used in the

current segment are stored in a data structure called USE table. The USE table holds the information such as name of the symbol, address, address relatively. The list of all symbols which are defined in the current segment and can be referred by the other segments are stored in a data structure called DEFINITION table. The definition table holds the information such as symbol, address. Example: SIC/XE relocating loader algorithm begin get PROGADDR from operating system while not end of input do begin read next record while record type = E do begin read next input record while record type=T then begin move object code from record to location ADDR+ specified address end while record type=M add PROGADDR at the location PROGADDR+ specified address end end end

8|P a ge

V Sem IT Advantages

CS 2304 System Software

This type of loading support uses multiple programs and multiple data segments. This type of loading scheme allows segments with reference to non local data or subroutines. Disadvantage It is necessary to allocate, relocate, link and load all the subroutine each time to execute a program. (b) Overlays Sometimes a program may require more storage space than the available one. Execution of such program can be possible if all the segments are not required simultaneously to be present in the main memory. In such situations only those segments are resident in the memory that is actually needed at the time of execution. The overall effect of this is efficiency of execution process gets degraded. The efficiency can then be improved by carefully selecting all the interdependent segments. The interdependency of the segments can be specified by a tree like structure is called overlay structure. The overlay structure contains multiple root, nodes and edges. Each node represents the segment. The specification of required amount of memory is also essential in this structure. The two segments can lie simultaneously in the main memory if they are on the same path. Example S1 (16 K)

S2 (14 K)

S3 (8 K)

S4 (20 K)

S5 (12 K)

S6 (16 K)

S7 (16 K)

S8 (12 K)

S9 (18 K)
9|P a ge

V Sem IT

CS 2304 System Software From the above figure some segments can reside in the memory simultaneously. Such

segments are called co-resident segments. Thus the total memory allocated is of 78 K with overlay structure whereas the memory requirement of entire program is 132 k. Thus lot much of space can be saved in storing the segments using overlay structure. The linker generates the description of static overlay structure in the form of table which is called as segment table. From the segment table itself it is decided whether to load particular segment or not. The segment table should be available during execution because during execution a control program called the overlay supervisor checks the segment table for every external reference. If the required segment is not loaded then the overlay supervisor calls the loader to load the required segment. And after loading the required segment the segment table is updated.

16

S1 S2 S3 S4 S5 S6

24

30 40 44

S7
60

72 78 80

S8

S9

10 | P a g e

V Sem IT

CS 2304 System Software

3. Write down and explain the algorithms for pass I and pass II of loaders. (16 Marks) May/June-2011 Algorithm for Pass I loader: begin get PROGADDR from operating system set CSA SDDR to PROGADDR {for first control section} while not end of input do begin read next input record {Header record for control section} set CSLTH to control section length search ESTAB for control section name if found then set error flag {duplicate external symbol} else enter control section name into ESTAB with value CSADDR while record type = E do begin read next input record if record type=D then for each symbol in the record do begin search ESTAB for symbol name if found then set error flag ( duplicate external symbol) else enter symbol into ESTAB with value (CSADDR+INDICATED address) end {for} end {while = E} add CSLTH to CSADDR {starting address for next control section} end {while not EOF} end {Pass 1}

11 | P a g e

V Sem IT

CS 2304 System Software During the first pass, the loader is concerned only with Header and Define record types in

the control sections. The beginning load address for the linked program (PROGADDR) is obtained from the operating system. This becomes the starting address (CSADDR) for the first control section in the input sequence. The control section name from the Header record is entered into ESTAB, with value given by CSADDR. All external symbols appearing in the Define record for the control section are also entered into ESTAB. Their addresses are obtained by adding the value specified in the Define record to CSADDR. When the End record is read, the control section length CSLTH is added to CSADDR. This calculation gives the starting address for the next control section in sequence. At the end of Pass 1, ESTAB contains all external symbols defined in the set of control sections together with the address assigned to each. Algorithm for Pass II loader: begin set CSADDR to PROGADDR set EXECADDR to PROGADDR while not end of input do begin read next input record { Header record} set CSLTH to control section length while record type = E do begin read next input record if record type = T then begin {if object code is in character from, convert into internal representation} move object code from record to location (CSADDR+ specified address) end {if T} else if record type = M then begin search ESTAB for modifying symbol name if found then add or subtract symbol value at location (CSADDR + specified address) else
12 | P a g e

V Sem IT set error flag (undefined external symbol) end {if M} end {while =E} if an address is specified {in End record} then set EXECADDR to (CSADDR + Specified address) add CSLTH to CSADDR end {while not EOF}

CS 2304 System Software

jump to location given by EXECADDR {to start execution of loaded program} End {Pass 2]

Pass 2 loader performs the actual loading, relocation and linking of the program. CSADDR is used in the same way it was in Pass 1 it always contains the actual starting address of the control section currently being loaded. As each Text record is read, the object code is moved to the specified

address. When a modification record is encountered, the symbol whose value is to be used for modification is looked up in ESTAB. This value is then added to or subtracted from the indicated location in memory. The last step performed by the loader is usually the transferring of control to the loaded program to begin execution. The end record for each control section may contain the address of the first instruction in that control section to be executed.

4. Discuss about the loader design options. (16 Marks) Loader design options are: Linkage Editors Dynamic Linking Bootstrap Loader Linkage Editors

May/June-2011,Nov/Dec-2011

The program which performs allocation, relocation and linking is called binder. The binder performs relocation, creates liked executable text and stores this text in a file in some systematic manner. Such kind of module prepared by the binder for execution is called load module. This load module can then be actually loaded in the main memory by the loader. This loader is also called as module loader.

13 | P a g e

V Sem IT

CS 2304 System Software If the binder can produce the exact replica of executable code in the load module then the

module loader simply loads this file into the main memory which ultimately reduces the overall time complexity. But in this process the binder should knew the current positions of the main memory. In multiprogramming environment, the region of main memory available for loading the program is decided by the host operating system. The binder should also know which memory area is allocated to the loading program and it should modify the relocation information accordingly. The binder which performs the linking function and produces adequate information about allocation and relocation and writes this information along with the program code in the file is called linkage editor. The module loader ten accepts this file as input, reads the information stored in and based on this information about allocation and relocation it performs the task of loading in the main memory. Even though the program is repeatedly executed the linking is done only once. Moreover, the flexibility of allocation and relocation helps efficient utilization of the main memory.

Object Program (s)

Linkage editor Library

Linked program

Relocating loader

Memory A linkage editor produces a linked version of the program, which is written to a file or library for later execution. When the user is ready to run the linked program, a simple relocating
14 | P a g e

V Sem IT

CS 2304 System Software

loader can be used to load the program into memory. The only object code modification necessary is the addition of an actual load address to relative values within the program. The linkage editor performs relocation of all control sections relative to the start of the linked program. Thus, all items that need to be modified at load time have values that are relative to the start of the linked program. This means that the loading can be accomplished in one pass with no external symbol table required. This involves much less overhead than using a linking loader. Dynamic Linking In overlay structure certain selective subroutines can be resident in the memory. That means it is not necessary to resident all the subroutines in the memory for all the time. Only necessary routines can be present in the main memory and during execution the required subroutines can be loaded in the memory. This process of postponing linking and loading of external reference until execution is called dynamic linking. For example, Suppose the subroutine main calls A,B,C,D then it is not desirable to load A,B,C and D along with the main in the memory. Whether A, B, C or D is called by the main or not will be known only at the time of execution. Hence keeping these routines already before are really not needed. In dynamic linking, the binder first prepares a load module in which along with program code the allocation and relocation information is stored. The loader simply loads the main module in the main memory. If any external reference to a subroutine comes, then the execution is suspended for a while, the loader brings the required subroutine in the main memory and then the execution process is resumed. Thus in dynamic linking both the loading and linking is done dynamically. In dynamic linking several executing programs share one copy of subroutine or library. This one copy of subroutine could be loaded into the memory. The program can make load-and-call service request to operating system. The program passes the symbolic name of the required subroutine as a parameter to the request made. The operating system then loads the required subroutine in the memory. This scenario is given by following figure.

15 | P a g e

V Sem IT

CS 2304 System Software

Dynamic loader in operating system

Request for subroutine ERR-MSG User Program

If the required subroutine is situated in library then the loader makes a call for that routine from library. The required routine gets loaded in the memory.

Dynamic loader

User Program

Library

ERR-MSG

16 | P a g e

V Sem IT

CS 2304 System Software Once the required subroutine is identified then the control is passed from operating system

to the routine which is being called.

Dynamic loader

User Program

ERR-MSG

The operating system (dynamic loader) then returns the control to user program from which request for subroutine was made. If second call to the same subroutine is made and if the same subroutine is still in the memory then dynamic loader simply passes control to subroutine.

Dynamic loader

User Program

ERR-MSG

17 | P a g e

V Sem IT Bootstrap Loader

CS 2304 System Software

A small program is written and stored in the ROM. This program initially loads the operating system from secondary storage to main memory. The operating system then takes the overall control. This program which is responsible for booting up the system is called bootstrap loader. This is the program which must be executed first when the system is first powered on. If the program starts from the location x then to execute this program the program counter of this machine should be loaded with the value x. Thus the task of setting the initial value of the program counter is to be done by machine hardware. The bootstrap loader is a very small program which is to be fitted in the ROM. The task of bootstrap loader is to load the necessary portion of the operating system in the main memory. The initial address at which the bootstrap loader is to be loaded is generally the lowest or the highest location. Various characteristics of bootstrap loader are: The bootstrap loader is a small program and it should be fitted in the ROM. The bootstrap loader must load necessary portion of operating system in the main memory. The initial address at which the bootstrap loader is to be loaded is generally the lowest for example at location 0000 or at the highest location and not at intermediate location. Example of Bootstrap loader Bootstrap loader is a first program that loads the operating system program in the memory. For example the bootstrap loader for SIC/XE is as given below

BOOT

START CLEAR LDX

0 A #128 GETC A,S S,4 GETC S,A 0,X X,X

Bootstrap loader for SIC/XE Clear A to zero Initialize register X to Hex 80 Read Hex digit from program being loaded Save in Register S Move to high order 4 bits of byte Get next Hex digit Combine digits to from one byte Store at address in register X Add 1 to memory address being loaded

LOOP

JSUB RMU SHIFTL JSUB ADDR STCH TIXR

18 | P a g e

V Sem IT J GETC TD JEQ RD COMP JEQ COMP JLT SUB COMP JLT SUB RETURN INPUT RSUB BYTE END X F1 LOOP LOOP INPUT GETC INPUT #4 80 #48 GETC #48 #10 RETURN #7 Otherwise subtract 7 Return to caller Code for input device

CS 2304 System Software Loop until end of input is reached Test input device Loop until ready Read character If character is Hex 04 Jump to start of program just loaded Compare to Hex 30 Skip character less than 0 Subtract Hex 30 from ASCII code If result is less than 10 conversion is complete

Here the bootstrap loader itself begins at address 0 in the memory and it loads the operating system starting at address 80. Each byte of object code to be loaded is represented on device F1 as two hexadecimal digits. The object code FROM device F1 is always loaded into consecutive bytes of memory. After loading of all the object code from device F1, bootstrap jumps to address 80, which ultimately begins the execution of program that was loaded. The subroutine GETC reads character from device F1 and converts it from ASCII code to value of hexadecimal digit.

5. Describe machine dependent loader features in detail. (16 Marks) The machine dependent assembler features are: Relocation Program Linking Algorithm and Data Structures for a Linking Loader

Nov/Dec-2011

19 | P a g e

V Sem IT Relocation

CS 2304 System Software

Relocation is the process of updating the addresses used in the address sensitive instructions of a program. It is necessary that such a modification should help to execute the program from designated of the memory. The assembler generates the object code. This object code gets executed after loading at storage locations. The addresses of such object code will get specified only after the assembly process is over. There are two types of addresses being generated: Absolute address and Relative address. The absolute address can be directly used to map the object code in the main memory. Whereas the relative address is only after the addition of relocation constant to the object code address. This kind of adjustment needs to be done in case of relative address before actual execution of the code. The typical example of relative reference is : addresses of the symbols defined in the Label field, addresses of the data which is defined by the assembler directive, literals, redefinable symbols. Similarly, the typical example of absolute address is the constants which are generated by assembler are absolute. The assembler calculates which addresses are absolute and which addresses are relative during the assembly process. During the assembly process the assembler calculates the address with the help of simple expressions. Example LOAD A(X) + 5 The expression A(X) means the address of variable X. The meaning of the above instruction is that loading of the contents of memory location which is 5 more than the address of variable X. Suppose if the address of X is 50 then by above command then we get the memory location is 50+5=55. Therefore as the address of variable X is relative A(X) +5 is also relative. To calculate the relative addresses the simple expressions are allowed. It is expected that the expression should posses at the most addition and multiplication operations. In the expression if the address is absolute then put 0 over there and if address is relative then put 1 over there. The expression then gets transformed to sum of 0s and
20 | P a g e

V Sem IT

CS 2304 System Software 1s. If the resultant value of the expression is 0 then e xpression is absolute. And if the resultant value of the expression is 1 then the expression is relative. If the resultant is other than 0 or 1 then the expression is illegal.

Program Linking A control section is a part of the program that maintains its identity after assembly. Each control section can be loaded and relocated independently of the others. Example Line 0000 Loc PROGA Source Statement START 0 EXTDEF LISTA, ENDA EXTREF LISTB, ENDB, LISTC, ENDC . . . LDA LISTA +LDT LISTB+4 LDX #ENDA-LISTA . . . EQU * . . EQU * WORD ENDA-LISTA+LISTC WORD ENDC-LISTC-10 WORD ENDC-LISTC+LISTA-1 WORD ENDA-LISTA-(ENDB-LISTB) WORD LISTB-LISTA END REF1 Source Statement START 0 EXTDEF LISTB, ENDB EXTREF LISTA, ENDA, LISTC, ENDC . . . LDA LISTA +LDT LISTB+4 LDX #ENDA-LISTA . . . Object code

0020 0023 0027

REF1 REF2 REF3

03201D 050014

0040

LISTA

0054 0054 0057 005A 005D 0060

ENDA REF4 REF5 REF6 REF7 REF8

000014 FFFFF6 00003F 000014 FFFFC0

Line 0000

Loc PROGA

Object code

0020 0023 0027

REF1 REF2 REF3

03201D 050014

21 | P a g e

V Sem IT 0040 LISTA EQU . . EQU WORD WORD WORD WORD WORD END *

CS 2304 System Software

0054 0054 0057 005A 005D 0060

ENDA REF4 REF5 REF6 REF7 REF8

* ENDA-LISTA+LISTC ENDC-LISTC-10 ENDC-LISTC+LISTA-1 ENDA-LISTA-(ENDB-LISTB) LISTB-LISTA

000014 FFFFF6 00003F 000014 FFFFC0

Line 0000

Loc PROGA

0020 0023 0027

REF1 REF2 REF3

0040

LISTA

0054 0054 0057 005A 005D 0060

ENDA REF4 REF5 REF6 REF7 REF8

Source Statement START 0 EXTDEF LISTC, ENDC EXTREF LISTA, ENDA, LISTC, ENDC . . . LDA LISTA +LDT LISTB+4 LDX #ENDA-LISTA . . . EQU * . . EQU * WORD ENDA-LISTA+LISTC WORD ENDC-LISTC-10 WORD ENDC-LISTC+LISTA-1 WORD ENDA-LISTA-(ENDB-LISTB) WORD LISTB-LISTA END

Object code

03201D 050014

000014 FFFFF6 00003F 000014 FFFFC0

Consider the three separately assembled programs in the above example. Each of which consists of a single control section. Each program contains a list of items LISTA, LISTB, LISTC. The ends of these lists are marked by the labels ENDA, ENDB, ENDC. The labels on the beginning and ends of the lists are external symbols. Consider the first reference REF1. For the first program (PROGA), REF1 is simply a reference to a label within the program. It is assembled in the usual way as a program counter relative instruction. No modification for relocation or linking is necessary.
22 | P a g e

V Sem IT

CS 2304 System Software The reference marked REF2 is processed in a similar manner. For PROGA, the operand expression consists of an external reference plus a constant. The assembler stores the value of the constant in the address field of the instruction and a modification record directs a loader to add to this field the value of LISTB. In PROGB, the same expression is simply a local reference and is assembled using a program counter relative instruction with no relocation or linking required. REF3 is an immediate operand whose value is to be the difference between ENDA and LISTA. In PROGA, the assembler has all of the information necessary to compute this value.

Algorithm and Data Structures for a Linking Loader The main data structure needed for linking loader is an external symbol table ESTAB. It is used to store the name and address of each external symbol in the set of control sections being loaded. The table also often indicates in which control section the symbol is defined. A hashed organization is typically used for this table. Two other important variables are PROGADDR (program load address) and CSADDR (control section address). PROADDR is the beginning address in memory where the linked program is to be loaded. Its value is supplied to the loader by the operating system. CSADDR contains the starting address assigned to the control section currently being scanned by the loader. This value is added to all relative addresses within the control section to convert them to actual addresses. The linking loader usually makes two passes over its input. In terms of general function, the two passes of a linking loader are quite similar to the two passes of an assembler. Pass 1 assigns addresses to all external symbols, and pass 2 performs the actual loading, relocation and linking.

6. a) Discuss the characteristics of an absolute loader. (8 Marks) The characteristics of an absolute loader are:

May/June-2012

Absolute loader is a kind of loader in which relocated object files are created, loader accepts these files and places them at specified location in the memory. This type of loader is called absolute because no relocation information is needed; rather it is obtained from the programmer or assembler.
23 | P a g e

V Sem IT

CS 2304 System Software The starting address of every module is known to the programmer, this corresponding starting address is stored in the object file, then task of loader becomes very simple and that is to simply place the executable form of the machine instructions at the locations mentioned in the object file. In this the programmer should take care of two things: First thing is specification of starting address of each module to be used. If some modification is done in some module then the length of that module may vary. These causes a change in the starting address of immediate next modules, then the programmer make necessary changes in the starting addresses of respective modules. Second thing is, while branching from one segment to another the absolute starting address of respective module is to be known by the programmer so that such address can be specified at respective JMP instruction. Algorithm for absolute loader: Input: Object codes and starting address of program segments Output: An executable code for corresponding source program. This executable code is to be placed in the main memory. Method: Begin For each program segment do Begin Read the first line from object module to obtain information about memory location. The starting address says S in corresponding object module is the memory location where executable code is to be placed. Hence Memory_location = S Line_counter = 1; as it is first line While (! End of file) For the current object code do Begin 5. Read next line 6. 7. Write line into location S S= S+1
24 | P a g e

V Sem IT 8. end end end Advantages: It is simple to implement Line_counter = Line_counter+1

CS 2304 System Software

The task of loader becomes simpler as it simply obeys the instruction regarding where to place the object code in the main memory. The process of execution is efficient. Disadvantages In this, the programmers duty to adjust all the inter segments addresses and manually do the linking activity. For that, it is necessary for a programmer to know the memory management. If at all any modification is done the some segments, the starting addresses of immediate next segments may get changed, the programmer has to take care of this issue and to update the corresponding starting addresses on any modification in the source.

6. b) Explain about the relocating loader. (8 Marks)

May/June-2012

The relocating loader cannot have the direct access to the source code. And to place the object code in the memory there are two situations: Either the address of the object code could be absolute which then can be directly placed at the specified location or the address can be relative. The assembler should give the following information to the loader The length of the object code segment The list of all the symbols which are not defined in the current segment but can be used in the current segment. The list of all the symbols which are defined in the current segment but can be referred by the other segments. The lists of symbols which are not defined in the current segment but can be used in the current segment are stored in a data structure called USE table. The USE table holds the information such as name of the symbol, address, address relatively.
25 | P a g e

V Sem IT

CS 2304 System Software The list of all symbols which are defined in the current segment and can be referred by the

other segments are stored in a data structure called DEFINITION table. The definition table holds the information such as symbol, address. Example: SIC/XE relocating loader algorithm begin get PROGADDR from operating system while not end of input do begin read next record while record type = E do begin read next input record while record type=T then begin move object code from record to location ADDR+ specified address end while record type=M add PROGADDR at the location PROGADDR+ specified address end end end Advantages This type of loading support uses multiple programs and multiple data segments. This type of loading scheme allows segments with reference to non local data or subroutines. Disadvantage It is necessary to allocate, relocate, link and load all the subroutine each time to execute a program.

26 | P a g e

V Sem IT 7. a) Describe the linking editors. (8 Marks)

CS 2304 System Software May/June-2012

The program which performs allocation, relocation and linking is called binder. The binder performs relocation, creates liked executable text and stores this text in a file in some systematic manner. Such kind of module prepared by the binder for execution is called load module. This load module can then be actually loaded in the main memory by the loader. This loader is also called as module loader. If the binder can produce the exact replica of executable code in the load module then the module loader simply loads this file into the main memory which ultimately reduces the overall time complexity. But in this process the binder should knew the current positions of the main memory. In multiprogramming environment, the region of main memory available for loading the program is decided by the host operating system. The binder should also know which memory area is allocated to the loading program and it should modify the relocation information accordingly. The binder which performs the linking function and produces adequate information about allocation and relocation and writes this information along with the program code in the file is called linkage editor. The module loader ten accepts this file as input, reads the information stored in and based on this information about allocation and relocation it performs the task of loading in the main memory. Even though the program is repeatedly executed the linking is done only once. Moreover, the flexibility of allocation and relocation helps efficient utilization of the main memory.

Object Program (s)

Linkage editor Library

Linked program

Relocating loader Memory

27 | P a g e

V Sem IT

CS 2304 System Software A linkage editor produces a linked version of the program, which is written to a file or

library for later execution. When the user is ready to run the linked program, a simple relocating loader can be used to load the program into memory. The only object code modification necessary is the addition of an actual load address to relative values within the program. The linkage editor performs relocation of all control sections relative to the start of the linked program. Thus, all items that need to be modified at load time have values that are relative to the start of the linked program. This means that the loading can be accomplished in one pass with no external symbol table required. This involves much less overhead than using a linking loader.

7. b) Discuss briefly about the MS-DOS linker. (8 Marks)

May/June-2012

MS-DOS (Microsoft-DOS) linker is a linkage editor that combines one or more object modules to produce a complete executable program. These object modules have the file name extension .obj. Each object module contains a binary image of the translated instructions and data of the program. It also describes the structure of the program. Object Module The object module is a sequence of records. The purpose of object record is to describe specific aspect of the program. The Microsoft Link supports 14 types of object records containing five basic categories of information (i) Binary image It is a code generated by translator. It is comprised of opcode, addresses and program data. It is basically an executable form of the object code. The linker builds the binary image of each object module. The binary image also describes the structure of the program. It guides the linker for combining all the related binary images stored in other object modules. (ii) External references For a single program many object modules can be prepared. It may happen that the reference used in one object module is defined in other object module. Such a reference is treated as external reference. (iii) Public definitions The public definitions are a list of all the public names of the symbols referred in a segment of the object module. Along with the binary image the object modules contain

28 | P a g e

V Sem IT

CS 2304 System Software information about the address references. The linker can make use of this information to resolve the address references. (iv) Debugging information The debugging information can be prepared using the line number in the corresponding source program. The executable code can refer such debugging information at the time of execution. (v) Miscellaneous information The object module can contain the comments, module identification information, and structure information of the object module. This information is also useful foe deciding which object modules can be combined together. Working of Linker The task of linker is to produce a binary program by performing relocation and linking. The binary program means executable file. When linker encounters the external symbols, it searches the references in the library file, as soon as these referenced modules are obtained. The set of object modules are linked and relocated. The process of locating the object modules by using the definitions from library files is called auto linking. The process of linking is done in two passes. In first pass the object modules are processed and the relevant information from corresponding segments and public definitions are collected. In the second pass the relocation and linking of the object modules is done.

8. a) Explain the functions of loader in detail. (8 Marks) Functions of loader are: Allocation Linking Relocation Loading Allocation:

Nov/Dec-2012

Loader allocates the space for program in the memory, by calculating the size of the program. This activity is called allocation.

29 | P a g e

V Sem IT Linking:

CS 2304 System Software

The loader resolves the symbolic references (code/data) between the object modules by assigning all the user subroutine and library subroutine addresses. This activity is called Linking. Relocation: There are some address dependent locations in the program, such address constants must be adjusted according to allocated space; such activity done by loader is called relocation. Loading: The Loader places all the machine instructions and data of corresponding programs and subroutines into the memory. Thus program now becomes ready for execution, this activity is called loading.

Source Program

Translator (Assembler)

Object program

Loader

Object program ready for execution

Memory 8. b) What is BOOTSTRAP loader? Explain its characteristics with examples. (8 Marks) Nov/Dec-2012 BOOTSTRAP loader: The bootstrap loader is a small program in ROM. Its task is to load the necessary portion of operating system in the main memory. Characteristics of Bootstrap loader: The bootstrap loader is a small program and it should be fitted in the ROM. The bootstrap loader must load necessary portion of operating system in the main memory.
30 | P a g e

V Sem IT

CS 2304 System Software The initial address at which the bootstrap loader is to be loaded is generally the lowest for example at location 0000 or at the highest location and not at intermediate location.

Example of Bootstrap loader Bootstrap loader is a first program that loads the operating system program in the memory. For example the bootstrap loader for SIC/XE is as given below

BOOT

START CLEAR LDX

0 A #128 GETC A,S S,4 GETC S,A 0,X X,X LOOP INPUT GETC INPUT #4 80 #48 GETC #48 #10 RETURN #7 X F1 LOOP

Bootstrap loader for SIC/XE Clear A to zero Initialize register X to Hex 80 Read Hex digit from program being loaded Save in Register S Move to high order 4 bits of byte Get next Hex digit Combine digits to from one byte Store at address in register X Add 1 to memory address being loaded Loop until end of input is reached Test input device Loop until ready Read character If character is Hex 04 Jump to start of program just loaded Compare to Hex 30 Skip character less than 0 Subtract Hex 30 from ASCII code If result is less than 10 conversion is complete

LOOP

JSUB RMU SHIFTL JSUB ADDR STCH TIXR J

GETC

TD JEQ RD COMP JEQ COMP JLT SUB COMP JLT SUB

Otherwise subtract 7 Return to caller Code for input device

RETURN INPUT

RSUB BYTE END

31 | P a g e

V Sem IT

CS 2304 System Software Here the bootstrap loader itself begins at address 0 in the memory and it loads the operating

system starting at address 80. Each byte of object code to be loaded is represented on device F1 as two hexadecimal digits. The object code FROM device F1 is always loaded into consecutive bytes of memory. After loading of all the object code from device F1, bootstrap jumps to address 80, which ultimately begins the execution of program that was loaded. The subroutine GETC reads character from device F1 and converts it from ASCII code to value of hexadecimal digit.

9. a) Explain dynamic linking in detail. (8 Marks)

Nov/Dec-2012

In overlay structure certain selective subroutines can be resident in the memory. That means it is not necessary to resident all the subroutines in the memory for all the time. Only necessary routines can be present in the main memory and during execution the required subroutines can be loaded in the memory. This process of postponing linking and loading of external reference until execution is called dynamic linking. For example, Suppose the subroutine main calls A,B,C,D then it is not desirable to load A,B,C and D along with the main in the memory. Whether A, B, C or D is called by the main or not will be known only at the time of execution. Hence keeping these routines already before are really not needed. In dynamic linking, the binder first prepares a load module in which along with program code the allocation and relocation information is stored. The loader simply loads the main module in the main memory. If any external reference to a subroutine comes, then the execution is suspended for a while, the loader brings the required subroutine in the main memory and then the execution process is resumed. Thus in dynamic linking both the loading and linking is done dynamically. In dynamic linking several executing programs share one copy of subroutine or library. This one copy of subroutine could be loaded into the memory. The program can make load-and-call service request to operating system. The program passes the symbolic name of the required subroutine as a parameter to the request made. The operating system then loads the required subroutine in the memory. This scenario is given by following figure.
32 | P a g e

V Sem IT

CS 2304 System Software

Dynamic loader in operating system

Request for subroutine ERR-MSG User Program

If the required subroutine is situated in library then the loader makes a call for that routine from library. The required routine gets loaded in the memory.

Dynamic loader

User Program

Library

ERR-MSG

33 | P a g e

V Sem IT

CS 2304 System Software Once the required subroutine is identified then the control is passed from operating system

to the routine which is being called.

Dynamic loader

User Program

ERR-MSG

The operating system (dynamic loader) then returns the control to user program from which request for subroutine was made. If second call to the same subroutine is made and if the same subroutine is still in the memory then dynamic loader simply passes control to subroutine.

Dynamic loader

User Program

ERR-MSG

34 | P a g e

V Sem IT 9. b) Compare linking loader and linkage editor. (8 Marks)

CS 2304 System Software Nov/Dec-2012

Linking Loader

Linkage Editor

Object Program (s) Object Program (s) Linkage editor Linking Loader Library Linked program Library

Memory

Relocating loader

Memory

Linking loader performs all linking and relocation operations, including automatic library search and loads the linked program directly into memory for execution. A linkage editor produces a linked version of the program which is written to a file or library for later execution. In linking loader, there is no need of relocating loader. In linkage editor, The relocation loader loads the load module into the memory The linking loader searches the libraries and resolves the external references every time the program is executed. In linkage editor, If a program is to be executed many times without being reassembled. Resolution of external references and library searching are only performed when the program is link edited. In linking loader, the loading may require two passes. In linkage editor, the loading can be accomplished in one pass.
35 | P a g e

V Sem IT

CS 2304 System Software

10. a) Why linking loader requires 2 passes to complete loading? Explain the operations of linking loader. (16 Marks) May/June-2013

The linking loader requires 2 passes to complete loading because, loader searches the libraries and resolves the external references every time the program is executed. Operations of linking loader: Operations are linking loader are: Program Linking Relocation Program Linking A control section is a part of the program that maintains its identity after assembly. Each control section can be loaded and relocated independently of the others.

Example Line 0000 Loc PROGA Source Statement START EXTDEF EXTREF . . . LDA +LDT LDX . . . EQU . . EQU WORD WORD WORD WORD WORD END 0 LISTA, ENDA LISTB, ENDB, LISTC, ENDC Object code

0020 0023 0027

REF1 REF2 REF3

LISTA LISTB+4 #ENDA-LISTA

03201D 050014

0040

LISTA

0054 0054 0057 005A 005D 0060

ENDA REF4 REF5 REF6 REF7 REF8

* ENDA-LISTA+LISTC ENDC-LISTC-10 ENDC-LISTC+LISTA-1 ENDA-LISTA-(ENDB-LISTB) LISTB-LISTA REF1

000014 FFFFF6 00003F 000014 FFFFC0

36 | P a g e

V Sem IT

CS 2304 System Software

Line 0000

Loc PROGA

0020 0023 0027

REF1 REF2 REF3

0040

LISTA

0054 0054 0057 005A 005D 0060

ENDA REF4 REF5 REF6 REF7 REF8

Source Statement START 0 EXTDEF LISTB, ENDB EXTREF LISTA, ENDA, LISTC, ENDC . . . LDA LISTA +LDT LISTB+4 LDX #ENDA-LISTA . . . EQU * . . EQU * WORD ENDA-LISTA+LISTC WORD ENDC-LISTC-10 WORD ENDC-LISTC+LISTA-1 WORD ENDA-LISTA-(ENDB-LISTB) WORD LISTB-LISTA END Source Statement START 0 EXTDEF LISTC, ENDC EXTREF LISTA, ENDA, LISTC, ENDC . . . LDA LISTA +LDT LISTB+4 LDX #ENDA-LISTA . . . EQU * . . EQU * WORD ENDA-LISTA+LISTC WORD ENDC-LISTC-10 WORD ENDC-LISTC+LISTA-1 WORD ENDA-LISTA-(ENDB-LISTB)

Object code

03201D 050014

000014 FFFFF6 00003F 000014 FFFFC0

Line 0000

Loc PROGA

Object code

0020 0023 0027

REF1 REF2 REF3

03201D 050014

0040

LISTA

0054 0054 0057 005A 005D

ENDA REF4 REF5 REF6 REF7

000014 FFFFF6 00003F 000014


37 | P a g e

V Sem IT 0060 REF8 WORD END LISTB-LISTA

CS 2304 System Software FFFFC0

Consider the three separately assembled programs in the above example. Each of which consists of a single control section. Each program contains a list of items LISTA, LISTB, LISTC. The ends of these lists are marked by the labels ENDA, ENDB, ENDC. The labels on the beginning and ends of the lists are external symbols. Consider the first reference REF1. For the first program (PROGA), REF1 is simply a reference to a label within the program. It is assembled in the usual way as a program counter relative instruction. No modification for relocation or linking is necessary. The reference marked REF2 is processed in a similar manner. For PROGA, the operand expression consists of an external reference plus a constant. The assembler stores the value of the constant in the address field of the instruction and a modification record directs a loader to add to this field the value of LISTB. In PROGB, the same expression is simply a local reference and is assembled using a program counter relative instruction with no relocation or linking required. REF3 is an immediate operand whose value is to be the difference between ENDA and LISTA. In PROGA, the assembler has all of the information necessary to compute this value.

Relocation Relocation is the process of updating the addresses used in the address sensitive instructions of a program. It is necessary that such a modification should help to execute the program from designated of the memory. The assembler generates the object code. This object code gets executed after loading at storage locations. The addresses of such object code will get specified only after the assembly process is over. There are two types of addresses being generated: Absolute address and Relative address. The absolute address can be directly used to map the object code in the main memory. Whereas the relative address is only after the addition of relocation constant to the object

38 | P a g e

V Sem IT

CS 2304 System Software code address. This kind of adjustment needs to be done in case of relative address before actual execution of the code. The typical example of relative reference is : addresses of the symbols defined in the Label field, addresses of the data which is defined by the assembler directive, literals, redefinable symbols. Similarly, the typical example of absolute address is the constants which are generated by assembler are absolute. The assembler calculates which addresses are absolute and which addresses are relative during the assembly process. During the assembly process the assembler calculates the address with the help of simple expressions.

Example LOAD A(X) + 5 The expression A(X) means the address of variable X. The meaning of the above instruction is that loading of the contents of memory location which is 5 more than the address of variable X. Suppose if the address of X is 50 then by above command then we get the memory location is 50+5=55. Therefore as the address of variable X is relative A(X) +5 is also relative. To calculate the relative addresses the simple expressions are allowed. It is expected that the expression should posses at the most addition and multiplication operations. In the expression if the address is absolute then put 0 over there and if address is relative then put 1 over there. The expression then gets transformed to sum of 0s and 1s. If the resultant value of the expression is 0 then expression is absolute. And if the resultant value of the expression is 1 then the expression is relative. If the resultant is other than 0 or 1 then the expression is illegal.

39 | P a g e

V Sem IT

CS 2304 System Software May/June-2013

11. a) Differentiate between linkage editor and linking loader. (10 Marks)

Linking Loader

Linkage Editor

Object Program (s) Object Program (s) Linkage editor Linking Loader Library Linked program Library

Memory

Relocating loader

Memory

Linking loader performs all linking and relocation operations, including automatic library search and loads the linked program directly into memory for execution. A linkage editor produces a linked version of the program which is written to a file or library for later execution. In linking loader, there is no need of relocating loader. In linkage editor, The relocation loader loads the load module into the memory The linking loader searches the libraries and resolves the external references every time the program is executed. In linkage editor, If a program is to be executed many times without being reassembled. Resolution of external references and library searching are only performed when the program is link edited. In linking loader, the loading may require two passes.
40 | P a g e

V Sem IT In linkage editor, the loading can be accomplished in one pass.

CS 2304 System Software

The linkage editor performs relocation of all control sections relative to the start of the linked program. This involves much less overhead than using a linking loader. If a program is to be executed many times without being reassembled, the use of of a linkage editor substantially reduces the overhead required.

11. b) Describe the various record types in MS-DOS linker. (6 Marks)

May/June-2013

Various record types in MS-DOS linker are: THEADR TYPDEF PUBDEF EXTDEF LNAMES SEGDEF GRPDEF LEDATA LIDATA FIXUPP MODEND - Relocation and linking information - End of object module - Translated instructions and data - Segment definition and grouping - External symbols and references - Translator header

The object file is a collection of object records. The format of each record is:

Record Type

Record Length

Name

Check-sum

The type field indicates a specific code for the type of object record being used. It occupies 1 byte of space. The Record length contains a number of bytes in the record exclusive of the first two fields. The Name field is a variable length field which is typically derived from the type of the object record. The Check-sum contains twos complement of the sum of all other bytes in the record.

41 | P a g e

V Sem IT The structure of MS-DOS object module is given below:

CS 2304 System Software

THEADR 80 H Length Module Name Check-sum

The THEADR is derived by translator (assembler) from the source file name. For reporting errors to the linker this name is being used.

LNAMES 96 H Length Name List Check-sum

The LNAMES record contains the Name List which consists of the names used by the SEGDEF.

SEGDEF 98H Length Relocation Attribute Segment Name Index Check-sum Length

The SEGDEF specifies the name of the segments by using the index into the Name list

EXTDEF 8CH Length List of external Check-sum references PUBDEF 90H Length Base specificaton The EXTDEF and PUBDEF records are definition records used specifically for external references. The field list of external references contains a list of external references made in the program of this module. Similarly PUBDEF record contains the list of public names used in the segment.
42 | P a g e

Name

Offset

Check-sum

V Sem IT

CS 2304 System Software

FIXUPP 9CH Length Loc code Fix data Frame data Target data Target offset The FIXUPP records are used to resolve the external references. Check-sum

MODEND 8AH Length Type Start address Check-sum

The MODEND record is a terminating record of the object module which is used to indicate end of the module. The Type field specifies whether the module is main module or not.

43 | P a g e

You might also like