CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science...
-
Upload
angel-baldwin -
Category
Documents
-
view
223 -
download
0
Transcript of CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science...
CS2422 Assembly Language and System Programming
Linking Loader
Department of Computer ScienceNational Tsing Hua University
3
Linking Loader
Input: a set of object programs to be linked Two passes (similar to assembler)
Pass 1: Assign addresses to all external symbols Pass 2: Perform actual loading, relocation, linking
ESTAB (external symbol table)
Control section Symbol Address LengthProgam A 4000 63
LISTA 4040ENDA 4054
Program B 4063 7FLISTB 40C3ENDB 40D3
Program C 40E2 51LISTC 4112ENDC 4124
+
+
4
Pass 1 Program Logic
Pass 1: Assign addresses to all external symbols
Variables and data structures PROGADDR (program load address) from OS CSADDR (control section address) CSLTH (control section length) ESTAB
Figure 3.11(a) Process Header and Define records
5
beginget PROGADDR from operating systemset CSADDR to PROGADDR (for first control sect.)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
Figure 3.11(a)
6
while record type 'E' do read next input record if record type = ‘D’ then for each symbol in the record do search ESTAB for symbol name if found then set error (dup external symbol) else enter symbol+value into ESTAB (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}
Figure 3.11(a)
7
Pass 2 Program Logic
Pass 2: Perform actual loading, relocation, and linking
Figure 3.11(b) Process Text and Modification record
Modification record Lookup the symbol in ESTAB
End record for a main program Transfer address
8
beginset CSADDR to PROGADDRset EXECADDR to PROGADDRwhile not end of input do 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 if object code is in character form, convert into internal rep. enter object code to location (CSADDR + specified address) end {if 'T'}
Figure 3.11(b)
9
else if record type = 'M' then search ESTAB for modifying symbol if found then add or subtract value at loc (CSADDR + specified address) else set error (undefined external symbol) end {if ‘M’} end {while 'E'} if address is specified {in End record} then set EXECADDR to (CSADDR + specified addr) add CSLTH to CSADDR end {while not EOF} jump to location given by EXECADDR (to start execution of loaded program)end {Pass 2}
Figure 3.11(b)
10
Improve Efficiency
Use local search instead of multiple searches of ESTAB for the same symbol Assign a reference number to each external
symbol Use reference number in Modification records
Implementation 01: Control section name Other: External reference symbols Need only read once and use an array to track
Example (Fig. 3.12)
11
Figure 3.12 (1/3)
Ref No. Symbol Address1 PROGA 40002 LISTB 40C33 ENDB 40D34 LISTC 41125 ENDC 4124
12
Figure 3.12 (2/3)
Ref No. Symbol Address1 PROGB 40632 LISTA 40403 ENDA 40544 LISTC 41125 ENDC 4124