 Today we are going to discuss the linker algorithm. We have seen the linker and its specifications in the last video. At the end of this session, students will be able to demonstrate the steps involved in designing a linker. When we look at the background, we see first the steps for execution, which include translation of a program, linking of the program from other programs needed for its execution, relocation of the program to execute from a specific memory area attached to it, and finally loading of the program in the memory for the purpose of execution. Here we see the schematic of how the procedure works. A source program is given to a translator which produces an object module. This object module is given to the linker for information that is required for linking, and a binary program is produced by the linker which is loaded by the loader into the main memory and data is supplied to it to produce the results. Let us now think and answer what is the information present in that object module that is input to the linker. We once again revisit the working of the system software where a source code is given to a file processor and is given to a compiler or assembler to produce the object file or the obj file, which is given as input to the linker and the loader loads the binary program produced by the linker into the main memory for execution. This object module contains all the information necessary to relocate and link the program with other programs. We have already understood what are the conditions of relocation in our previous video and therefore object module consists of four components a header that contains translated origin size and execution start address of a program P. A program contains a machine language program corresponding to this program P and a relocation table reloc tab describing the instruction requiring relocations and each entry containing the field of a translated address of the address sensitive instruction and the linking table link tab contains information concerning public definitions and external references. A linking table has three fields a symbol which has a symbolic name type which is a public definition or an external reference. A translated address if public definition or address of the first memory of the word allocated and if it is external reference then it is the address of the memory word containing the reference of the symbol. Let us first understand what is done in relocation therefore we treat this algorithm separately as a relocation algorithm. The program linked origin is different from that which is produced by the linker command. Therefore for each object module we have translated origin is equal to translated origin of the object module. The object module size is the size of the object module. We apply a relocation factor and find out where the program has to be relocated. We read the machine language program in the work area which is an example program and we read the relocatable table of an object module and for each entry in the relocatable table we have translated address assigned to the address of the relocation entry and address in the work area assigned to the address of the work area plus translated address minus the translated origin. And then we add relocation factor to the operand address in the word with the address in the work area. And finally the program linked origin is assigned to the program linked origin and added to the object module size. When we talk about linking let us first understand the requirements. All program units are translated separately. All sub-programs call the common variable reference required for linking and programs are nested in the main program. Procedure reference do not require linking. They can be handled using only relocation. Built-in functions require linking and the linker processes all object modules being linked and builds a table of all public definitions and load time addresses. Now we go for understanding that linking also requires a name table which contains the symbol name for external references or object module and linked address for public definitions that contain link address for object module contains the link origin. Therefore most of the information in the end tab is derived from the link tab entries with the type public definition. The algorithm for linking consists of program linked origin is assigned to the link origin which is got by the linker command and for each object module t origin is equal to translated origin of the object module size plus the size of the object module and the relocation factor is then calculated and assigned to the program linked origin minus t origin value and we read the machine language program in the work area and we read the link table of the object module. For each of the link table entry with the type public definition we assign the symbol to the name and we assign linked address to translated address plus the relocation factor which we have calculated and we enter the name and the linked address in the end tab. We enter object module name program linked origin in the end tab and program linked origin is assigned to program linked origin plus object module size. For each object module now we do t origin is equal to translated origin of the object module for each link tab entry with the type is equal to external the address in the work area is assigned the address of the work area plus program linked origin minus linked origin plus translated address minus t origin. The search symbol in the end tab and copy its linked address add the linked address to the operand address in the word with the address address in the work space. As an example let us consider for an instruction requiring relocation IRR it is set to the instruction that performs relocation of the program. So our steps include calculation the relocation factor RF add it to the translation time address for every instruction which is the member of instruction requiring relocation. For example the relocation for a particular example program is 900 minus 500 is equal to 400 and IRR contains the translated address 540 and 538 which are instruction and reading of A. The address is changed to 540 plus 400 is equal to 940 and 538 plus 400 is equal to 938. Here we are adding the relocation factor 400. For the previous given assembly program object module contains following information translated origin given as 500 the size being 42 and external string being added as 500. Therefore for the machine language instruction which is given we now have the relocation table which looks as we have shown here and the linking table as we have shown here having external and public definition addresses. A loop is not here as it is not a public definition. Let the address of the work area be now 300 while relocation of the object module relocation factor being 400 for the first relocation table the address in the work area is 300 plus the 500 minus 500 which is 300 and this word contains the instruction of the read A. It is relocated by adding 400 to operand address in it. For the second relocation table entry address in the work area is 300 plus 538 minus 500 is equal to 338 and the instruction in this word is similarly located by adding 400 to the operand address in it. All these calculations are done and then we go while linking the program P the program Q with the origin 900 as shown here and tab contains the following information the work area being 300 then link tab of alpha is processing during the link address in the work area as 300 plus the 900 minus the 900 plus 518 which minus 500 which is 318 hence linked address of alpha is 973 and this is copied from n-tab entry of alpha and added to the word in the address 318 for our references we have used thank you