38
Chapter 6: Loaders Mrs. Sunita M Dol (Aher), Assistant Professor, Computer Science and Engineering Department, Walchand Institute of Technology, Solapur, Maharashtra

Chapter 6 Loaders

Embed Size (px)

Citation preview

Page 1: Chapter 6 Loaders

Chapter 6: Loaders

Mrs. Sunita M Dol (Aher),Assistant Professor,

Computer Science and Engineering Department,Walchand Institute of Technology, Solapur, Maharashtra

Page 2: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 2

• Function of loader• General loader scheme• Absolute loader• Relocating loader• Direct linking loader• Dynamic loading

6. Loaders

Page 3: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 3

• Function of loader• General loader scheme• Absolute loader• Relocating loader• Direct linking loader• Dynamic loading

6. Loaders

Page 4: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 4

• Loader– The loader is a program which accepts the object

program decks, prepare these program for execution by the computer and initiates the execution.

Function of Loader

Page 5: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 5

• Loader

Function of Loader

Program A

Program B

Loader

Databases

B

A

Programs loaded in memoryready for execution

Figure: General loading scheme

Page 6: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 6

• Four Functions of Loader– Allocation : allocate space in memory for program.– Linking: resolve symbolic references between object

decks– Relocation: adjust all address dependent locations such

as address constants to corresponds to allocated space.– Loading : physically place the machine instruction and

data into memory.

Function of Loader

Page 7: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 7

• Types of Loader– “Compile and Go” Loader– General Loader scheme– Absolute Loader– Relocating Loader– Direct Linking Loader– Dynamic Loader

Loader Scheme

Page 8: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 8

• The assembler runs in one part of memory and it place the assembled machine instruction and data directly into their assigned memory locations.

• When the assembly is completed, the assembler causes a transfer to starting instruction of the program.

• The loader consist of one instruction that transfers to the starting instruction of newly assembled program.

“Compile and Go” Loader

Page 9: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 9

“Compile and Go” Loader

Source program deck

Compile and go translator Program

loaded in memory

Assembler

MemoryFigure: Compile and Go loader scheme

Page 10: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 10

• Advantages– Easy to implement– No extra procedure

• Disadvantages– A portion of memory is wasted.– It is necessary to retranslate the user’s program deck

every time it is run.– Difficult to handle multiple segment written in different

languages.

“Compile and Go” Loader

Page 11: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 11

• Function of loader• General loader scheme• Absolute loader• Relocating loader• Direct linking loader• Dynamic loading

6. Loaders

Page 12: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 12

• The loader accepts the assembled machine instruction, data and other information present in object format and places machine instruction and data in core in an executable computer form.

• The loader is assumed to be smaller so that more memory is available to user.

• Reassembly is no longer necessary to run the program at later stage.

General Loader Scheme

Page 13: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 13

Figure: General loader scheme

General Loader Scheme

Loader Object program ready for execution

Loader

Memory

Source Program

Source Program

Translator

Translator

Object program 1

Object program 1

Page 14: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 14

• Function of loader• General loader scheme• Absolute loader• Relocating loader• Direct linking loader• Dynamic loading

6. Loaders

Page 15: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 15

• The assembler outputs the machine language translation of the source program.

• The data is punched on the cards instead of being placed directly in memory.

• The loader accepts the machine text and places it in the core at the location prescribed by the assembler.

Absolute Loader

Page 16: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 16

Absolute LoaderMAIN Program Location Instruction

MAIN START 100

BALR 12,0 100 BALR 12,0

USING MAIN+2, 12 102 .

. . .

. . .

L 15, ASQRT 120 L 15, 142(0, 12)

BALR 14,15 124 BALR 14, 15

. . .

. . .

ASQRT DC F’400’ 244 F’400’

END 248

Page 17: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 17

Absolute Loader

SQRT SUBROUTINE Location Instruction

SQRT START 400 400

USING *, 15 . .

. . .

. . .

BR 14 476 BCR 15, 14

Page 18: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 18

Figure: Absolute loader

Absolute Loader

AbsoluteLoader MAIN

SQRT

Memory

MAIN

SQRT

Page 19: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 19

• Advantages– Simple to implement– More core available to user

• Disadvantages– The programmer must specify to the assembler the

address in core where the program is to be loaded.– If there are multiple subroutine then the programmer

must remember address of each.

Absolute Loader

Page 20: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 20

• Four loader function – Allocation by programmer– Linking by programmer– Relocation by assembler– Loading by loader

Absolute Loader

Page 21: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 21

• Function of loader• General loader scheme• Absolute loader• Relocating loader• Direct linking loader• Dynamic loading

6. Loaders

Page 22: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 22

• The assembler assembles each procedure segment independently.

• The output of a relocating assembler is– the object program and information about all other

programs it references– Relocation information i.e. the locations which are

dependent on the core allocation.• For each source program, the assemblers output

a machine translation of the program prefixed by a transfer vector.

Relocating Loader

Page 23: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 23

Relocating Loader

Source Program

Program length = 48 bytes

Transfer vector = 8 bytes

Rel. addr. Relocation Object code

MAIN START

EXTRN SQRT 0 00 ‘SQRT’

EXTRN ERR 4 00 ‘ERRb’

ST 14, SAVE 8 01 ST 14, 36

L 1, =F’9’ 12 01 L 1, 40

BAL 14, SQRT 16 01 BAL 14, 0

C 1, =F’3’ 20 01 C 1, 44

BNE ERR 24 01 BC 7, 4

L 14, SAVE 28 01 L 14, 36

BR 14 32 0 BCR 15, 14

SAVE DS F 34 0 (Skipped for alignment)

END 36 00 (Temporary location)

40 00 9

44 00 3

Page 24: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 24

Relocating Loader

SQRT

Memory

ERR

BC 14, 448BC 15, 526ST 14, 436L 1, 440BAL 14, 400C 1, 444BC 7, 404L 4, 436BCR 15, 14(Temp Loc)

93

Relative Address

.048

121620242832364044

Absolute Address

.400404408412416420424428432436440444

.

.526

.

.

Page 25: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 25

• The four functions of loader were performed by the loader.– Allocation bits to solve the problem of relocation– Transfer vector to solve the problem of linking– Program length to solve the problem of allocation

• Disadvantages– Not suited for loading and storing external data.– Transfer vector increases the size of object program in

memory.– Does not provide facility to access data segments that

can be shared

Relocating Loader

Page 26: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 26

• Function of loader• General loader scheme• Absolute loader• Relocating loader• Direct linking loader• Dynamic loading

6. Loaders

Page 27: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 27

• The assembler must give the loader the following information with each procedure or data segment– The length of the segment– A list of all the symbols in the segment that may be

referenced by other segment and their relative location within the segment.

– A list of symbols not defined in the segment but referenced in the segment.

– Information as where address constants are located in the segment and a description of how to revise their values.

– The machine code translation of the source program and the relative addresses assigned.

Direct Linking Loader

Page 28: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 28

Program Translation

Card No. Rel. Loc.1 JOHN START2 ENTRY RESULT3 EXTRN SUM4 BALR 12, 0 0 BALR 12, 05 USING *, 106 ST 14, SAVE 2 ST 14, 54(0, 12)7 L 1, POINTER 6 L 1, 46(0, 12)8 L 15, ASUM 10 L 15, 58(0, 12)9 BALR 14, 15 14 BALR 14, 15

10 ST 1, RESULT 16 ST 1, 50(0, 12)11 L 14, SAVE 20 L 14, 54(0, 12)12 BR 14 24 BCR 15, 14

26 ----13 TABLE DC F’1, 7, 9, 10, 3’ 28 1

32 736 940 1044 3

14 POINTER DC A(TABLE) 48 2815 RESULT DS F 52 ----16 SAVE DS F 56 ----17 ASUM DC A(SUM) 60 ?18 END 64

Page 29: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 29

• The assembler produce four types of cards– ESD (External Symbol Directory)– TXT (Text Card)– RLD (Relocation and Linkage Directory)– END

Direct Linking Loader

Page 30: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 30

• ESD (External Symbol Directory)– This card contain information about

• all symbols that are defined in this program but that may be referenced elsewhere and

• all symbols referenced in this program but defined elsewhere

– ‘Type’ mnemonic in ESD card can be• SD (Segment Definition)• LD (Local Definition)• ER (External Reference)

Relocating Loader

Page 31: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 31

• ESD (External Symbol Directory)– ESD card for example

Relocating Loader

Reference no.

Symbol Type Relative location

Length

1 JOHN SD 0 64

2 RESULT LD 52 ----

3 SUM ER ---- ----

Page 32: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 32

• TXT card– This card contain actual object code translated version

of the source program.

Direct Linking Loader

Page 33: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 33

• TXT card exampleReference number Relative location Object code

4 0 BALR 12, 0

6 2 ST 14, 54(0, 12)

7 6 L 1, 46(0, 12)

8 10 L 15, 58(0, 12)

9 14 BALR 14, 15

10 16 ST 1, 50(0, 12)

11 20 L 14, 54(0, 12)

12 24 BCR 15, 14

13 28 1

13 32 7

13 36 9

13 40 10

13 44 3

14 48 28

17 60 0

Direct Linking Loader

Page 34: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 34

• RLD card– This card contain following information

• The location of each constant that needs to be changed due to relocation

• By what it has to be changed• The operation to be performed

– RLD card example

Reference no.

Symbol Flag Length Relative location

14 JOHN + 4 4817 SUM + 4 60

Direct Linking Loader

Page 35: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 35

• Function of loader• General loader scheme• Absolute loader• Relocating loader• Direct linking loader• Dynamic loading

6. Loaders

Page 36: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 36

• Dynamic loading

Dynamic Loading

100 K

A (20K)

B (20K)

C (30K)

D (10K)

E (20K)

Figure: Subroutine calls between procedure

Page 37: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 37

• Dynamic loading

Dynamic Loading

Figure: Overlay structure

A (20K)

B (20K) D (10K)

C (30K) E (20K)

Page 38: Chapter 6 Loaders

05/03/2023 Mrs. Sunita M Dol, CSE Dept. 38

• Dynamic loading

Dynamic Loading

Figure: Possible storage assignment of each procedure

A (20K)

B (20K)D (10K)

C (30K)E (20K)