Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.

Similar presentations


Presentation on theme: "CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University."— Presentation transcript:

1 CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University

2 1 Today ’ s Topics  Beck ’ s Section 3.2.3: Algorithm and Data Structure for a Linking Loader

3 2 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) + +

4 3 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 4 begin get PROGADDR from operating system set 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 5 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 6 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 7 begin set CSADDR to PROGADDR set EXECADDR to PROGADDR while 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 8 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 9 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 10 Figure 3.12 (1/3)

12 11 Figure 3.12 (2/3)

13 12 Figure 3.12 (3/3)


Download ppt "CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University."

Similar presentations


Ads by Google