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 can‟t 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

Because assembler is placed at one part of the memory and loader simply loads assembled machine instructions into the memory. After completion of assembly process loader contains the instruction using which the location counter is set to the start of the newly assembled program. it‟s a FORTRAN compiler which uses such “load and go” scheme. 5|P a ge . (8 Marks) a) Assemble-and-go loader CS 2304 System Software Nov/Dec-2010 In this type of loader. The example is WATFOR-77. Explain the following (a) Assemble-and-go loader. its machine code is obtained and it is directly put in the main memory at some known address. (8 Marks) (b) Absolute loader. This loading scheme is also called as “compile and go loader”.V Sem IT PART B (16 Marks) 1. the instruction is read line by line. User Program Assemble and go Loader Program for execution Assembler Advantage This type of loader is simple to implement. 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.

rather it is obtained from the programmer or assembler. then the programmer make necessary changes in the starting addresses of respective modules.V Sem IT Disadvantages CS 2304 System Software The Assemble-and-go loader is a combination of assembler and loader activities. Second thing is. 6|P a ge . this corresponding starting address is stored in the object file. For a programmer it is very difficult to make an orderly modulator program and also it becomes difficult to maintain such program. 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. loader accepts these files and places them at specified location in the memory. this combination program occupies large block It cannot handle multiple source programs or multiple programs written in different languages. and the “Assemble and go loader” cannot handle such programs. This type of loader is called absolute because no relocation information is needed. (b) Absolute loader Absolute loader is a kind of loader in which relocated object files are created. The starting address of every module is known to the programmer. 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. This is because assembler can translate one source language to other target language. The execution time will be more in this loader as every time program is assembled and then executed. These causes a change in the starting address of immediate next modules. 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.

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. 7|P a ge Nov/Dec-2010 . 4. end end end Write line into location S S= S+1 Line_counter = Line_counter+1 2.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. Read next line 2. (8 Marks) (a) Relocating loader The relocating loader cannot have the direct access to the source code. (8 Marks) (b) Overlays. Explain the following: (a) Relocating loader. as it is first line While (! End of file) For the current object code do Begin 1. 3. 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 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.

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 definition table holds the information such as symbol. The list of all the symbols which are defined in the current segment but can be referred by the other segments. 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 . address. The USE table holds the information such as name of the symbol. address relatively. address. 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 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 efficiency can then be improved by carefully selecting all the interdependent segments. Disadvantage It is necessary to allocate. In such situations only those segments are resident in the memory that is actually needed at the time of execution. The specification of required amount of memory is also essential in this structure. 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 . relocate. link and load all the subroutine each time to execute a program.V Sem IT Advantages CS 2304 System Software This type of loading support uses multiple programs and multiple data segments. Each node represents the segment. The two segments can lie simultaneously in the main memory if they are on the same path. (b) Overlays Sometimes a program may require more storage space than the available one. The overall effect of this is efficiency of execution process gets degraded. This type of loading scheme allows segments with reference to non local data or subroutines. nodes and edges. The interdependency of the segments can be specified by a tree like structure is called overlay structure. Execution of such program can be possible if all the segments are not required simultaneously to be present in the main memory. The overlay structure contains multiple root.

Such segments are called co-resident segments. The linker generates the description of static overlay structure in the form of table which is called as segment table. Thus the total memory allocated is of 78 K with overlay structure whereas the memory requirement of entire program is 132 k. From the segment table itself it is decided whether to load particular segment or not.V Sem IT CS 2304 System Software From the above figure some segments can reside in the memory simultaneously. Thus lot much of space can be saved in storing the segments using overlay structure. And after loading the required segment the segment table is updated. If the required segment is not loaded then the overlay supervisor calls the loader to load the required segment. 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. 16 S1 S2 S3 S4 S5 S6 24 30 40 44 S7 60 72 78 80 S8 S9 10 | P a g e .

(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 . Write down and explain the algorithms for pass I and pass II of loaders.V Sem IT CS 2304 System Software 3.

the control section length CSLTH is added to CSADDR. the loader is concerned only with Header and Define record types in the control sections. When the End record is read. with value given by CSADDR. The control section name from the Header record is entered into ESTAB. All external symbols appearing in the Define record for the control section are also entered into ESTAB. 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.V Sem IT CS 2304 System Software During the first pass. This becomes the starting address (CSADDR) for the first control section in the input sequence. This calculation gives the starting address for the next control section in sequence. Their addresses are obtained by adding the value specified in the Define record to CSADDR. The beginning load address for the linked program (PROGADDR) is obtained from the operating system. 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 . ESTAB contains all external symbols defined in the set of control sections together with the address assigned to each. At the end of Pass 1.

relocation and linking is called binder. 4. 13 | P a g e . the object code is moved to the specified address. This loader is also called as module loader. 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. The last step performed by the loader is usually the transferring of control to the loaded program to begin execution. (16 Marks) Loader design options are: Linkage Editors Dynamic Linking Bootstrap Loader Linkage Editors May/June-2011. This value is then added to or subtracted from the indicated location in memory. As each Text record is read. The binder performs relocation.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. Discuss about the loader design options. This load module can then be actually loaded in the main memory by the loader. creates liked executable text and stores this text in a file in some systematic manner. When a modification record is encountered.Nov/Dec-2011 The program which performs allocation. Such kind of module prepared by the binder for execution is called load module. the symbol whose value is to be used for modification is looked up in ESTAB. relocation and linking of the program. The end record for each control section may contain the address of the first instruction in that control section to be executed.

the region of main memory available for loading the program is decided by the host operating system. which is written to a file or library for later execution. reads the information stored in and based on this information about allocation and relocation it performs the task of loading in the main memory. 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. a simple relocating 14 | P a g e . The binder should also know which memory area is allocated to the loading program and it should modify the relocation information accordingly. Even though the program is repeatedly executed the linking is done only once.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. Moreover. The module loader ten accepts this file as input. In multiprogramming environment. When the user is ready to run the linked program. Object Program (s) Linkage editor Library Linked program Relocating loader Memory A linkage editor produces a linked version of the program. But in this process the binder should knew the current positions of the main memory. the flexibility of allocation and relocation helps efficient utilization of the main memory.

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

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 .

Dynamic loader User Program ERR-MSG 17 | 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.

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. This program which is responsible for booting up the system is called bootstrap loader.A 0. This program initially loads the operating system from secondary storage to main memory. For example the bootstrap loader for SIC/XE is as given below BOOT START CLEAR LDX 0 A #128 GETC A.V Sem IT Bootstrap Loader CS 2304 System Software A small program is written and stored in the ROM. The initial address at which the bootstrap loader is to be loaded is generally the lowest or the highest location.S S. Thus the task of setting the initial value of the program counter is to be done by machine hardware. This is the program which must be executed first when the system is first powered on. The bootstrap loader must load necessary portion of operating system in the main memory. The operating system then takes the overall control. The task of bootstrap loader is to load the necessary portion of the operating system in the main memory. The bootstrap loader is a very small program which is to be fitted in the ROM. Various characteristics of bootstrap loader are: The bootstrap loader is a small program and it should be fitted in the ROM.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 . 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.4 GETC S.

(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 . After loading of all the object code from device F1.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. 5. The subroutine GETC reads character from device F1 and converts it from ASCII code to value of hexadecimal digit. which ultimately begins the execution of program that was loaded. Describe machine dependent loader features in detail. 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. bootstrap jumps to address 80.

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

Each control section can be loaded and relocated independently of the others. And if the resultant value of the expression is 1 then the expression is relative. . ENDB. . . If the resultant value of the expression is 0 then e xpression is absolute. 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 . ENDA EXTREF LISTB. ENDC . . . LDA LISTA +LDT LISTB+4 LDX #ENDA-LISTA . LISTC. ENDA. . ENDC . EQU * . If the resultant is other than 0 or 1 then the expression is illegal. 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. . . LDA LISTA +LDT LISTB+4 LDX #ENDA-LISTA .V Sem IT CS 2304 System Software 1‟s. . Example Line 0000 Loc PROGA Source Statement START 0 EXTDEF LISTA. LISTC. Program Linking A control section is a part of the program that maintains its identity after assembly. ENDB EXTREF LISTA.

The ends of these lists are marked by the labels ENDA.V Sem IT 0040 LISTA EQU . . The labels on the beginning and ends of the lists are external symbols. . It is assembled in the usual way as a program counter relative instruction. ENDB. . . For the first program (PROGA). LISTB. ENDA. LISTC. EQU * . ENDC . 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. REF1 is simply a reference to a label within the program. Each of which consists of a single control section. Each program contains a list of items LISTA. ENDC EXTREF LISTA. . No modification for relocation or linking is necessary. LDA LISTA +LDT LISTB+4 LDX #ENDA-LISTA . 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. ENDC. 22 | P a g e . LISTC. Consider the first reference REF1. .

relocation and linking. This type of loader is called absolute because no relocation information is needed. loader accepts these files and places them at specified location in the memory. 6. Two other important variables are PROGADDR (program load address) and CSADDR (control section address). the two passes of a linking loader are quite similar to the two passes of an assembler. the assembler has all of the information necessary to compute this value. In terms of general function. rather it is obtained from the programmer or assembler. the same expression is simply a local reference and is assembled using a program counter relative instruction with no relocation or linking required. Algorithm and Data Structures for a Linking Loader The main data structure needed for linking loader is an external symbol table ESTAB. CSADDR contains the starting address assigned to the control section currently being scanned by the loader.V Sem IT CS 2304 System Software The reference marked REF2 is processed in a similar manner. Pass 1 assigns addresses to all external symbols. In PROGA. It is used to store the name and address of each external symbol in the set of control sections being loaded. 23 | P a g e . In PROGB. the operand expression consists of an external reference plus a constant. 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. 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. a) Discuss the characteristics of an absolute loader. The table also often indicates in which control section the symbol is defined. and pass 2 performs the actual loading. (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. 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. For PROGA. A hashed organization is typically used for this table. REF3 is an immediate operand whose value is to be the difference between ENDA and LISTA.

this corresponding starting address is stored in the object file. If some modification is done in some module then the length of that module may vary. Method: Begin For each program segment do Begin Read the first line from object module to obtain information about memory location. Second thing is. The starting address says S in corresponding object module is the memory location where executable code is to be placed. Write line into location S S= S+1 24 | P a g e . This executable code is to be placed in the main memory. In this the programmer should take care of two things: First thing is specification of starting address of each module to be used. 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. then the programmer make necessary changes in the starting addresses of respective modules.V Sem IT CS 2304 System Software The starting address of every module is known to the programmer. Algorithm for absolute loader: Input: Object codes and starting address of program segments Output: An executable code for corresponding source program. These causes a change in the starting address of immediate next modules. Hence Memory_location = S Line_counter = 1. 7. Read next line 6. as it is first line While (! End of file) For the current object code do Begin 5. 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.

it is necessary for a programmer to know the memory management. Disadvantages In this. 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. 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 process of execution is efficient. 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 programmer‟s duty to adjust all the inter segments addresses and manually do the linking activity. the programmer has to take care of this issue and to update the corresponding starting addresses on any modification in the source. 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. If at all any modification is done the some segments. 6. For that. 25 | P a g e . the starting addresses of immediate next segments may get changed. address. (8 Marks) May/June-2012 The relocating loader cannot have the direct access to the source code. b) Explain about the relocating loader. The USE table holds the information such as name of the symbol. address relatively.V Sem IT 8.

26 | P a g e . link and load all the subroutine each time to execute a program. address.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. Disadvantage It is necessary to allocate. This type of loading scheme allows segments with reference to non local data or subroutines. The definition table holds the information such as symbol. relocate. 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.

In multiprogramming environment. (8 Marks) CS 2304 System Software May/June-2012 The program which performs allocation. This loader is also called as module loader. But in this process the binder should knew the current positions of the main memory. relocation and linking is called binder. The binder performs relocation. the region of main memory available for loading the program is decided by the host operating system. 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. a) Describe the linking editors. Even though the program is repeatedly executed the linking is done only once. 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. creates liked executable text and stores this text in a file in some systematic manner. 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 . Moreover. 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. The binder should also know which memory area is allocated to the loading program and it should modify the relocation information accordingly.V Sem IT 7. reads the information stored in and based on this information about allocation and relocation it performs the task of loading in the main memory. The module loader ten accepts this file as input.

It guides the linker for combining all the related binary images stored in other object modules. This means that the loading can be accomplished in one pass with no external symbol table required. Thus. which is written to a file or library for later execution. It also describes the structure of the program. The linkage editor performs relocation of all control sections relative to the start of the linked program. (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. addresses and program data. Such a reference is treated as external reference. 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. These object modules have the file name extension . Each object module contains a binary image of the translated instructions and data of the program. (ii) External references For a single program many object modules can be prepared. all items that need to be modified at load time have values that are relative to the start of the linked program. b) Discuss briefly about the MS-DOS linker. Object Module The object module is a sequence of records. The only object code modification necessary is the addition of an actual load address to relative values within the program. This involves much less overhead than using a linking loader. 7. a simple relocating loader can be used to load the program into memory. When the user is ready to run the linked program. The purpose of object record is to describe specific aspect of the program. The binary image also describes the structure of the program. The linker builds the binary image of each object module. Along with the binary image the object modules contain 28 | P a g e . It is basically an executable form of the object code.V Sem IT CS 2304 System Software A linkage editor produces a linked version of the program.obj. It may happen that the reference used in one object module is defined in other object module. (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. It is comprised of opcode.

This information is also useful foe deciding which object modules can be combined together. 29 | P a g e . The set of object modules are linked and relocated. as soon as these referenced modules are obtained. (v) Miscellaneous information The object module can contain the comments. Working of Linker The task of linker is to produce a binary program by performing relocation and linking. 8. The binary program means executable file. module identification information. In first pass the object modules are processed and the relevant information from corresponding segments and public definitions are collected. (8 Marks) Functions of loader are: Allocation Linking Relocation Loading Allocation: Nov/Dec-2012 Loader allocates the space for program in the memory. In the second pass the relocation and linking of the object modules is done. This activity is called allocation. (iv) Debugging information The debugging information can be prepared using the line number in the corresponding source program. a) Explain the functions of loader in detail. The process of locating the object modules by using the definitions from library files is called auto linking. The executable code can refer such debugging information at the time of execution. by calculating the size of the program. The linker can make use of this information to resolve the address references. it searches the references in the library file. and structure information of the object module. The process of linking is done in two passes. When linker encounters the external symbols.V Sem IT CS 2304 System Software information about the address references.

this activity is called loading. such activity done by loader is called relocation. This activity is called Linking. Its task is to load the necessary portion of operating system in the main memory. Relocation: There are some address dependent locations in the program. (8 Marks) Nov/Dec-2012 BOOTSTRAP loader: The bootstrap loader is a small program in ROM. Thus program now becomes ready for execution. Characteristics of Bootstrap loader: The bootstrap loader is a small program and it should be fitted in the ROM. b) What is BOOTSTRAP loader? Explain its characteristics with examples. 30 | P a g e . The bootstrap loader must load necessary portion of operating system in the main memory. Loading: The Loader places all the machine instructions and data of corresponding programs and subroutines into the memory.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. such address constants must be adjusted according to allocated space. Source Program Translator (Assembler) Object program Loader Object program ready for execution Memory 8.

Example of Bootstrap loader Bootstrap loader is a first program that loads the operating system program in the memory.S S.X X.A 0.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.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 .4 GETC S. For example the bootstrap loader for SIC/XE is as given below BOOT START CLEAR LDX 0 A #128 GETC A.

then the execution is suspended for a while. This scenario is given by following figure. Hence keeping these routines already before are really not needed. The operating system then loads the required subroutine in the memory.C. bootstrap jumps to address 80. The loader simply loads the main module in the main memory. B. 32 | P a g e . This process of postponing linking and loading of external reference until execution is called dynamic linking.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. 9. This one copy of subroutine could be loaded into the memory. After loading of all the object code from device F1. That means it is not necessary to resident all the subroutines in the memory for all the time. the binder first prepares a load module in which along with program code the allocation and relocation information is stored. Only necessary routines can be present in the main memory and during execution the required subroutines can be loaded in the memory. the loader brings the required subroutine in the main memory and then the execution process is resumed. The program passes the symbolic name of the required subroutine as a parameter to the request made. The subroutine GETC reads character from device F1 and converts it from ASCII code to value of hexadecimal digit. In dynamic linking. (8 Marks) Nov/Dec-2012 In overlay structure certain selective subroutines can be resident in the memory. Each byte of object code to be loaded is represented on device F1 as two hexadecimal digits. a) Explain dynamic linking in detail.C and D along with the main in the memory. which ultimately begins the execution of program that was loaded. The object code FROM device F1 is always loaded into consecutive bytes of memory.D then it is not desirable to load A. The program can make load-and-call service request to operating system. Suppose the subroutine main calls A. If any external reference to a subroutine comes. Whether A. In dynamic linking several executing programs share one copy of subroutine or library. For example.B.B. Thus in dynamic linking both the loading and linking is done dynamically. C or D is called by the main or not will be known only at the time of execution.

Dynamic loader User Program Library ERR-MSG 33 | 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 ERR-MSG 34 | P a g e . 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 The operating system (dynamic loader) then returns the control to user program from which request for subroutine was made.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.

the loading can be accomplished in one pass. In linkage editor. A linkage editor produces a linked version of the program which is written to a file or library for later execution. 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. In linking loader. including automatic library search and loads the linked program directly into memory for execution. If a program is to be executed many times without being reassembled. In linking loader.V Sem IT 9. Resolution of external references and library searching are only performed when the program is link edited. In linkage editor. In linkage editor. there is no need of relocating loader. the loading may require two passes. 35 | P a g e . 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.

ENDA LISTB. Example Line 0000 Loc PROGA Source Statement START EXTDEF EXTREF . . Each control section can be loaded and relocated independently of the others. . 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. . EQU . 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 . EQU WORD WORD WORD WORD WORD END 0 LISTA. ENDB. .V Sem IT CS 2304 System Software 10. 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. . LISTC. loader searches the libraries and resolves the external references every time the program is executed. LDA +LDT LDX .

. . . LDA LISTA +LDT LISTB+4 LDX #ENDA-LISTA . 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. ENDA. ENDB EXTREF LISTA. . . EQU * . . LDA LISTA +LDT LISTB+4 LDX #ENDA-LISTA . ENDC EXTREF LISTA. EQU * . ENDA. LISTC. LISTC. . . ENDC .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. ENDC . 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 . . .

No modification for relocation or linking is necessary. 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. Each of which consists of a single control section. The reference marked REF2 is processed in a similar manner. REF3 is an immediate operand whose value is to be the difference between ENDA and LISTA. For the first program (PROGA). It is necessary that such a modification should help to execute the program from designated of the memory. It is assembled in the usual way as a program counter relative instruction. LISTC. The absolute address can be directly used to map the object code in the main memory. The assembler generates the object code. In PROGB. The ends of these lists are marked by the labels ENDA.V Sem IT 0060 REF8 WORD END LISTB-LISTA CS 2304 System Software FFFFC0 Consider the three separately assembled programs in the above example. ENDC. The labels on the beginning and ends of the lists are external symbols. the assembler has all of the information necessary to compute this value. Each program contains a list of items LISTA. Consider the first reference REF1. REF1 is simply a reference to a label within the program. the same expression is simply a local reference and is assembled using a program counter relative instruction with no relocation or linking required. Whereas the relative address is only after the addition of relocation constant to the object 38 | P a g e . There are two types of addresses being generated: Absolute address and Relative address. ENDB. Relocation Relocation is the process of updating the addresses used in the address sensitive instructions of a program. LISTB. For PROGA. 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. the operand expression consists of an external reference plus a constant. In PROGA.

39 | P a g e . This kind of adjustment needs to be done in case of relative address before actual execution of the code. the typical example of absolute address is the constants which are generated by assembler are absolute. During the assembly process the assembler calculates the address with the help of simple expressions. The assembler calculates which addresses are absolute and which addresses are relative during the assembly process. The typical example of relative reference is : addresses of the symbols defined in the Label field. To calculate the relative addresses the simple expressions are allowed. Suppose if the address of X is 50 then by above command then we get the memory location is 50+5=55. In the expression if the address is absolute then put 0 over there and if address is relative then put 1 over there.V Sem IT CS 2304 System Software code address. redefinable symbols. Similarly. literals. addresses of the data which is defined by the assembler directive. 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. It is expected that the expression should posses at the most addition and multiplication operations. If the resultant value of the expression is 0 then expression is absolute. The expression then gets transformed to sum of 0‟s and 1‟s. And if the resultant value of the expression is 1 then the expression is relative. Therefore as the address of variable X is relative A(X) +5 is also relative. Example LOAD A(X) + 5 The expression A(X) means the address of variable X. If the resultant is other than 0 or 1 then the expression is illegal.

Resolution of external references and library searching are only performed when the program is link edited. the loading may require two passes. there is no need of relocating loader. In 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. a) Differentiate between linkage editor and linking loader. including automatic library search and loads the linked program directly into memory for execution.V Sem IT CS 2304 System Software May/June-2013 11. If a program is to be executed many times without being reassembled. In linkage editor. A linkage editor produces a linked version of the program which is written to a file or library for later execution. 40 | P a g e . In linking 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.

It occupies 1 byte of space. 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. The Record length contains a number of bytes in the record exclusive of the first two fields.Relocation and linking information . b) Describe the various record types in MS-DOS linker.Segment definition and grouping .External symbols and references . CS 2304 System Software The linkage editor performs relocation of all control sections relative to the start of the linked program. the loading can be accomplished in one pass. The Name field is a variable length field which is typically derived from the type of the object record. If a program is to be executed many times without being reassembled. The Check-sum contains two‟s complement of the sum of all other bytes in the record.End of object module .Translator header The object file is a collection of object records. 11.V Sem IT In linkage editor.Translated instructions and data . This involves much less overhead than using a linking loader. 41 | P a g e . (6 Marks) May/June-2013 Various record types in MS-DOS linker are: THEADR TYPDEF PUBDEF EXTDEF LNAMES SEGDEF GRPDEF LEDATA LIDATA FIXUPP MODEND . the use of of a linkage editor substantially reduces the overhead required.

42 | P a g e Name Offset Check-sum . LNAMES 96 H Length Name List Check-sum The LNAMES record contains the Name List which consists of the names used by the SEGDEF. Similarly PUBDEF record contains the list of public names used in the segment. For reporting errors to the linker this name is being used.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. 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.

43 | P a g e . 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.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.