13
4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra« 1/13 ptucse.loremate.com/sp/node/6 S\stem Programming Recommend 1.5k Press Ctrl & '+' To enlarge te[t and pics! ChapWeUV Home Topics Chapter 1 : Basics of S\stem Programming Chapter 2 : Editors Chapter 3 : Assemblers Chapter 4 : Compilers Chapter 5 : Debugger Chapter 6 : Linkers, Loaders, Micro-language, Microprocessor & Programming Language Chapter 6 : Part 2 Chapter 6 : Part 3 Chapter 6 : Part 4 Chapter 7 : Operating S\stem Home ChapWeU 6 : LinkeUV, LoadeUV, MacUo LangXage, MacUopUoceVVoU and PUogUamming LangXage (PaUW 1) Q 1 In a two pass direct linking loader what is the function of pass—I? Ans The main task of loader is to load a source program into its memory and then prepare it for further execution In pass-I of direct link loaders allocates segment and define symbols for lexical analysis Each symbol in this phase assigned to next available location after the preceding segment in order to minimise amount of storage required for the total program Hence, pass-I deals with only for allocate segment end defining symbols Therefore, pass I of direct link loader the limited scope and is oblized and mainly deals for allocation of segment and defining of symbols Q 2 At what point of time do the direct linking loading scheme perform binding? Ans. Direct line loader basically deals with allocating of segments and defining symbols as a part of lexical analysis for pass-I It performs binding in pass-lI By binding we mean that linking the subroutines and addresses Aftei allocation of locations and external symbols by pass-I, it is easy to complete loading and linking Hence, direct link loader perfoims binding at load time Q 3 At what point of time do the absolute loader scheme perform binding¶ Ans The loader loads a source program into memory and then prepares it for further execution Absolute loader distinguishes from othcr types of loader, as it performs binding before run-time By binding we mean that linking the subroutines and addresses Both linking and loading are performed in absolute loader scheme and the execution of that particular program begins. Hence, binding in case of absolute loader scheme performs µbinding as well as execution of a program

Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

Embed Size (px)

Citation preview

Page 1: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

1/13ptucse.loremate.com/sp/node/6

System Programming

Recommend 1.5k

Press Ctrl & '+' To enlarge text and pics!

Chapters

Home

Topics

Chapter 1 : Basics of System

Programming

Chapter 2 : Editors

Chapter 3 : Assemblers

Chapter 4 : Compilers

Chapter 5 : Debugger

Chapter 6 : Linkers, Loaders,

Micro-language,

Microprocessor &

Programming Language

Chapter 6 : Part 2

Chapter 6 : Part 3

Chapter 6 : Part 4

Chapter 7 : Operating System

Home

Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor andProgramming Language (Part 1)

Q 1 In a two pass direct linking loader what is the functionof pass—I?

Ans The main task of loader is to load a source program into itsmemory and then prepare it for further execution In pass-I ofdirect link loaders allocates segment and define symbols for lexicalanalysis Each symbol in this phase assigned to next availablelocation after the preceding segment in order to minimise amountof storage required for the total program Hence, pass-I deals withonly for allocate segment end defining symbols Therefore, pass Iof direct link loader the limited scope and is oblized and mainlydeals for allocation of segment and defining of symbols

Q 2 At what point of time do the direct linking loadingscheme perform

binding?

Ans. Direct line loader basically deals with allocating of segmentsand defining symbols as a part of lexical analysis for pass-I Itperforms binding in pass-lI By binding we mean that linking thesubroutines and addresses Aftei allocation of locations and externalsymbols by pass-I, it is easy to complete loading and linkingHence, direct link loader perfoims binding at load time

Q 3 At what point of time do the absolute loader schemeperform binding’

Ans The loader loads a source program into memory and thenprepares it for further execution Absolute loader distinguishes fromothcr types of loader, as it performs binding before run-time Bybinding we mean that linking the subroutines and addresses Bothlinking and loading are performed in absolute loader scheme andthe execution of that particular program begins. Hence, binding incase of absolute loader scheme performs ‘binding as well asexecution of a program

Page 2: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

2/13ptucse.loremate.com/sp/node/6

Q. 4 What is loading of a program?

Ans. Loading The loading is a process of preparing given objectdue for execution

and moving it to the main memory for further execution Loadingrefers to following set of functions:

(1) Loading : In loading, it places the machine instructions anddata into main memory for further operation.

(ii) Linking : The linking process resolves the symbolic referencesexisting between the object decks.

(iii) Allocating : The allocation process concerned with allocatingmemory for programmes.

(iv) Relocation: it adjusts all address dependent locations tocorresponding allocated addresses.

(v) Execution This module prepares the input program for furtherexecution.

Q. 5. List advantages of binding at load time over bindingat assembly time.

Ans. Binding basically deals with allocating segments and definingsymbols as a part of lexical analysis. It perform binding duringpass-Il. By binding we mean linking the subroutines andaddresses. After allocating locations and external symbols bypassI. Hence it is easy to complete loading and linkingsimultaneously. The advantages of binding at load band overbinding at assembly for is as follows:

(i) Dead lock avoidance : The pre-emptivéness of processes leadsto better multi— programming.

(ii) Less memory required : The execution of program larger thanavaiLable memory is possible.

(iii) It leads to more time complexity than others.

(iv) Better utilization of memory : Since during binding at loadtime, there is no wastage of memory due to unused instructionsand linkages. Hence memory is

better utilized.

(v) Increased throughout : The central processing unit is betterutilized and thus increases throughout.

Q. 6. At what point of time does direct linking loader (DLL)perform binding?

Ans. Binding is basically deals with allocating segments anddefining symbols as a part of lexical analysis. It performs bindingduring Pass-Il. By binding we mean linking the subroutines andaddresses. After allocating location and external symbol by pass-I.

Page 3: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

3/13ptucse.loremate.com/sp/node/6

Hence, it links together all the object modules and necessarylibraries to produce an output, which is executable binaryprogram.

Q. 7. Is it true that call leads to transfer of control to macrodefinition?

Ans. A macro call does it lead to transfer to control macrodefinition. We are not using control transfer whereas body ofmacro and macro definition is inserted into object program. Inaddition to it, macro code and macro processor replaces it bymacro body. After this event, control of statement moved to theinstruction. Hence the macro call does not lead to transfer tocontrol macro definition.

Q. 8. What are advantages of direct linking loader?

Ans. The main task of loader is to load a source program intomemory and prepares it for further execution. In pass-I direct linkloader allocates segments and define symbols for lexical analysis.Each symbol in the phase assigned to next available location afterproceeding. segment in order to minimize the amount of storagerequired for the total program. Hence pass-i deals with only forallocating segment and defining symbols

therefore pass-I of Direct Link Loader (DLL) is limited scope and isoblized to mainly

deals for allocation of segment and defining symbols..

Q. 9. List the functions of loaders.

Ans. The loaders accepts object program decks, prepare programfor execution and

initiate it. In this loader perform function of loading objectprogram from secondary memory devices arid also generateaddress and relocation information for loader.

Advantages:

(i) This makes more core available to user, since assembler is notin memory at load

time.

(ii) Absolute loader are very simple to implement.

(iii) It loads program in memory and make the program to readyfor executives.

Disadvantages:

(i) The programmer has to specify to assembler the address toload program.

(ii) The programmer has to remember address of subroutines tobe used in subroutine

linkage.

Page 4: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

4/13ptucse.loremate.com/sp/node/6

Q. 10. What is the role of a linker in program execution?

Ans. As the loader performs the following functions

1. Allocation of space in memory for programs. - and

2. Resolving symbolic references between object decks. with

3. Adjust all address dependent locations such as addressconstants.

4. Place the machine instructions and data into memory.

So. the linker plays a very important role in it. For example,consider the concept of is subroutine linkage. Here, a mainprogram A wishes to transfer to subprogram B.

The user in program A transfer instruction to program B as;

BAL14, B

However assembler does not knows value of this symbol referenceand declare an used error. Using the concept of linkage pseudo-opwe can remove this error.

Q. 11. Define loader, go”.

Ans. Definition : The loader is a program which accepts the objectprogram decks, the prepares these programs for execution by thecomputer, and initiates the execution of program.

e.g. user’s source program decks are usually converted to objectprogram decks (machine language) by assemblers and compilers.

Q. 12. What are the various functions performed by theloaders? Explain.

Ans. Functions: In particular, the loader must perform thesefunctions:

1. Allocate spare in memory for the programs (allocation).

2. Resolve symbolic references between objects decks (linking).

3. Adjust all address, dependent locations, such as addressconstants, to correspond to the allocated space (relocation).

4. Physically place the machine instructions and data intomemory (loading).

5. Performing all operations and machine instruction onoperator and operands.

Page 5: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

5/13ptucse.loremate.com/sp/node/6

Most of the examples used in this section are based upon IBMSystem! 370 assembler

and loader Several of the alternative loader schemes discussedare based upon computers

with a fixed-word, direct-address instruction format, such as theIBM 7094, IBM 1130,

UNIVAC 1108 and GE 635.

Q. 13. What are the Compile-and-Co loaders ? Explain.

Ans. Compile-and-Go” Loaders ‘Ohe method of performing theloader functions is to have the assembler run in one part ofmemory and place the assembled machine instructions and data,as they are ässembled, directly into their assigned memorylocations. When the assembly is completed, the assembler causesa transfer to the starting instruction of the program. This is asimple solution, involving no extra procedures. It is used by theWATFOR FORTRAN compiler and several other languageprocessers

Such a loading scheme is commonly called “compile-and-go” or“assemble-andgo”. It is relatively easy to implement. Theassembler simply places the code into core, and the “loader”consists of one instruction that transfers to the starting instructionof the newly assembled program

Page 6: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

6/13ptucse.loremate.com/sp/node/6

Q 14. What are the various advantages and disadvantagesof dynamic linking’

Ans An advantage here is that noverhead is incu i red unless theprocedure to be called or referenced as actually used A furtheradvantage is that system can be dynamically reconfigured Themajor drawback to using this type of loading scheme is theconsiderable overhead and complexity incurred, due to the factthat we have postponed most of the binding process untilexecution time.

Q. 15. What is the general loader scheme? Explain.

Ans. General loader Scheme :‘ The use, of an object deck asintermediate data to avoid one disadvantage of the preceding“compile-and-go” scheme requires the addition. of a new programto the system, •a loader. The loader accepts the assembledmachine instructions, data, and other information present in theobject format, and places’ machine instructions and data in core inan executable computer form. The loader is assumed to be,smaller than the assembler, so that more memory is’ available tothe user. A further advantage is that reassembly is no longernecessary to run the program at a later date.

Q 16 What are the functions performed by absolute loadingscheme Explain

Ans The four loader functions are accomplished as follows in anabsolute loading

scheme:

1 Allocation-by programmer

2 Linking-by programmer

3 Relocation-by assembler

Page 7: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

7/13ptucse.loremate.com/sp/node/6

4 Loading-by loader

Q 17 What are the uses of multiple entry points’

Ans The uses of multiple entry points are

I Common coding

Example SIN and COS involve basically the same computationsand could employ different entry points of the same routine.

2. Collecting together related routines for convenience.

3. Better or convenient access to common data base.

Q 18 What are subroutine reference or extern pseudo-ops’

Ans. SUBROUTINE REFERENCE (EXTRN PSEUDO-OP)

Assembler symbols are either internal or external External meansthat their value is not known to the assembler but will be providedby the loader—the action of the loader wilibe discussed in thefollowing section.

EXTRN El, E2, etc.

defines El, E2, etc. as external symbols to be used in addressconstants.

Q. 19. What do you meant by macro instructions?

Ans Macro Instructions

The “macro” is an abbreviation for a sequence of operations.Consider the following program:

Page 8: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

8/13ptucse.loremate.com/sp/node/6

A macro facility allows us to attach a name to this sequence and touse this name in

its place. We can invent a macro language that allows us to specifythe above as a macro definition and allows us to the definitionlater. We have chosen to use a 360-type macro language.

Q 20 What are macro processor

Ans. A macro processor effectively constitutes a separatelanguage processor with its own language.

It has been formed as allows:

Q. 21. What are the various macro instruction processorthat it perform?

Ans. There are four basic tasks that any macro instructionprocessor must perform.

I Recognize macro definitions A macro instruction processor mustrecognize macro definitions idenfified by the MACRO and MENDpseudo-ops. This task can be complicated when macro definitionsappear within macros When MACROs and MENDs are nested, as inthe example of the previous section, the macro processor mustrecognize the nesting and correctly match the last or outer MENDwith the first MACRO. All of the intervening text, including nestedMACROs and MENDs, defines a single macro instruction.

Page 9: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

9/13ptucse.loremate.com/sp/node/6

2. Save the definitions: The processor must store macroinstruction definitions, which it will need for expanding macro calls.

3 Recognize calls The processor must recognize macros calls thatappear as operation mnemonics This suggests that macro namesbe handled as a type of op-code.

4 Expand calls and substitute arguments The processor mustsubstitute for dummy or macro definition arguments thecoiresponding arguments from a macro call the resulting symbolic(in this case, asscmbly language) text is then substituted for themacro call I his text of coursL, may contain additional macrodefinitions or calls.

Q 22 What are the databases used in macro processor

Ans Specification of Data Bases The following data bases are usedby the two passes of the macro processor

Pass I data bases

I The input macro source deck

2 The output macro source deck copy for use by pass2

3. The Macro Definition Table (MDT), used to store the body of themacro definitions

4 The Macro Name Table (MNT), used to store the names ofdefined macros

5 The Macro Definition Table Counter (MDTC), used to indicate thenext aviable

entry in the MDT

6. The Macro Name Table Counter (MNTC), used to indicate thenext available entry in the MNT.

7 The Argument List Array (ALA), used to substitute index markersfor dummy

arguments before storing a macro definition

Pass 2 data bases

1 The copy of the input macro source deck

2 The output expanded source deck to be used as input to theassembler

3 The Macro Definition Table (MDT), created by passi

4 The Macro Name Table (MNT), created by passi

5 The Macro Definition Table Pointer (MDTP), used to indicate thenext line of

text to be used during macro expansion

6 The Argument List Array (ALA), used to substitute macro callarguments for

Page 10: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

10/13ptucse.loremate.com/sp/node/6

the index markers in the stored macro definition

7 Stop

Q 23 What are storage classes Explain

Ans Storage classes PL/I offers the programmcr three classes ofstorage (1) static, (2) automatic, and (3) controlled

Static storage is permanent and is assigned at compile time Staticis the only

storage available m many programming languages such asFORTRAN

Automatic storage is allocated only when the procedure or blockreferencing it is being executed For example if there is aprocedure SUBR with an automatic variable A on the first callSUBR will be assigned a location for A When the procedure isexited, A’s space will be released for possible use by otherprocedui es It is possible that a different location will be assignedto A for each call to SUBR A is automatic storage and is assignedautomatically at execution time

Q 24 What is the block structure facility provided byprogramming languages

Ans When a declaration of a variable is made in a program, thereis a certain welldefined region of the program to which thisdeclaration is applicable The block structure facility, inprogramming languages such as PL/I and ALGOL, controls thescope of declaration of variables Figure illustrates the use of thesefeatures (The reference numbers are not part of the program Theyare only used to refer to specific imes in the explanation)

In the outer block of the PL/I program in Figure 6.3, the variablesS,X and N are defined as integers (fixed-point binary numbers); bydefault all variables in PL,/I are assumed to be automatic unlessexplicitly declared otherwise. This program has an inner block thatextends from reference numbers 3 to 6. In the inner block thearray A and variable X are declared to be real floating-pointnumbers; since these variables are automatic storage, they areonly allocatedspace when the inner block is entered. This example

Page 11: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

11/13ptucse.loremate.com/sp/node/6

illustrates several points:

1. This program has two different variables named X but only oneis in use at any time, as defined by the block structure.

2. The array A is declared to be N locations long where N is aninteger that was already defined in the outer block.

3 The statement X S sets the variable X, defined in statement 4,equal to the current value of the variable S, defined in statement2. Since these variables are of different data types, PL/I willautomatically convert the value of S to a floating- pointrepresentation.

Q. 25. What are the various instruction formats availableon 8086? Explain with examples.

Ans An instruction format is composed of two parts

(i) Operation code (opcode) and

(u) Operands

opcode specifies the task to be performed by the computer andoperand is the data to be operated on The instruction formatspecifies how the opcode and operand are being present in aninstruction

for example c a + b

where c a and b are operands

where +, are operators

The format of an instruction can be of 8 bit or 16 bit. According tothe word size, the

Intel 8085, 8086 and 8088 instructions are classified into threeformats:

(a) One byte instruction

(b) Two byte mstruction

(c) Three byte instruction

(a) One byte instruction:

(a) One byte instruction:

(1) ADD B : This instruction adds the contents of register B into theaccumulator. For example 100,00,000 is binary form with 80H asan opcode. First five bits

10000 specify ADD operation and last three bits 000 are code forregister B.

The operand is assumed to be in accumulator.

(ii) MOV A, B This instruction moves the contents of register A. Forexample 7814 is an opcode for MOV A, B. The binary form of 78His 01111000. The

first two bits 01 are meant for MOV operation, the next three 111

Page 12: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

12/13ptucse.loremate.com/sp/node/6

bits are

binary code for register B.

(iii) RAL: This instruction rotates the contents of accumulator toleft by one

bit, For example 17 is an opcode for RAL.

(iv) HLT : This instruction stops the program, opcode for HLT is 76for Intel

8085.

(b) Two Byte instruction:

(i) MVI A, 05 : This instruction moves register 05 to register A. Incode form it

is written as 3E, 05. The first byte instruction is 3E. This code is forMVI A.

The second byte for instruction is 05 is data to be placed in A.

(ii) MOV B, A: This instruction moves content of register A to B. Incode

form it is written as 47.

(c) Three Byte Instruction:

(i) LDA : This instruction loads the cäntents of particular memoryaddress to

accumulator.

For example 3A, 50, FC. This instruction (LDA, IC5OH) loadsaccumulator

with contents of memory ldcation FC5OH.

(ii) LXI: The instruction LXI loads the contents FC5OH to .-.L pair.For example:

21, 50 FC is opcode for LXI. 5C50H. This instruct (LXI H, FC5O)will place

FC5OH in HT pair.

Q. 26. Describe the function of each of the RLD, ESD, TXTand END card in a loader.

Ans. In case of a loader, the object deck must contain allinformation needed for

relocation and linking. There are four sections to the objects deckand thus four

corresponding card formats as under:

(i) External Symbol Dictionary card (ESD.

(ii) instructions and data card, called “text” of program (TXT).

(ii)

Page 13: Chapter 6 _ Linkers, Loaders, Macro Language, Macro Processor and Programming Language (Part 1) _ System Programming

4/25/12 Chapter 6 : Linkers, Loaders, Macro Language, Macroprocessor and Progra…

13/13ptucse.loremate.com/sp/node/6

(iii) Relocation and Linkage Directory card (RLD)

(iv) End card (END).

The functions of listed cards of icIer an be e ned as under

(i) ESD card : ES!) conins infoimahon necessary to build symboltable. External symbols are the symbols that can be reierred evenoutside subroutines. Three types of external symbols are thereviz;

(a) Segment Definition (SD)

b) Local Definition (LD) and

(c) External Reference (ER).

RLD card: Each SD and symbol is assigned a one byte long uniquenumber, called symbol identifier, or ID RiD cards use this ID ofexternal symbols to save memory (8 bytes) occupied by symbolsnames. The RLD cards contain the following information:

(a) The location and length of each address constant that needs tobe changed for relocation or linking.

(b) The external symbol by which the address constant should hemodified

(c) The add or subtract operation that is to be performed.

(iii TXT card: it contains block of data and relative address atwhich the data is to be placed. For loading, the loader just has toadd the Program Load Address (PLA) to the relative address andthe data into the resulting location. The TXT cards may haveinstructions, non-relocated data, or initial values of addressconstants

(iv) End card : It specifies the end of the object deck. if assemblerEND card has a symbol in operand field, it specifies a start ofexecution point for all subroutines. This address is recorded on theEND card of the loader So in the nut shell,

RLD,ESD, TXT and END card must contain all information neededfor relocation and linking.