Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Assembly Language Level

Similar presentations


Presentation on theme: "The Assembly Language Level"— Presentation transcript:

1 The Assembly Language Level
Part C – Linking and Loading

2 Linking and loading Note that we didn’t write System.out.println() or Math.sin() (Java) or printf() or sin() (C/C++). Where is the code for these function? By what mechanism are we able to call them?

3 Linking and Loading Generation of an executable binary program from a collection of independently translated source procedures requires using a linker. Note: Translator causes a level change but linker does not. Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved

4 Purpose of linker To collect separately translated functions and data and link them to run as a unit (executable binary program). ILC (Instruction Location Counter) starts at 0 when assembling each module. But 2 or more modules can’t all start at 0 in the executable. Linker’s job is to resolve this via relocation.

5 Tasks Performed by the Linker (1)
Each module has its own address space, starting at 0. Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved

6 Tasks Performed by the Linker (1)
Each module has its own address space, starting at 0. Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved

7 Relocation problem Each object module represents a separate address space. We need a single, linear address space.

8 Linker steps: Construct a table of all the object modules and their lengths. Assign a starting address to each object module. For all instructions that reference memory, add a relocation constant equal to the starting address of the module. For all instructions that reference other procedures, insert the address of these procedures in place.

9 Linker steps: Construct a table of all the object modules and their lengths. Assign a starting address to each object module. For all instructions that reference memory, add a relocation constant equal to the starting address of the module. For all instructions that reference other procedures, insert the address of these procedures in place. module length starting address A B C D

10 Tasks Performed by the Linker (5)
X Note: Exe’s are often linked to start above address 0 to catch bad pointers and for other special purposes. The object modules of Fig after being positioned in the binary image but before being relocated and linked. Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved

11 Tasks Performed by the Linker (6)
The same object modules after linking and after relocation has been performed. Together they form an executable binary program, ready to run. Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved

12 Structure of an Object Module
The internal structure of an object module produced by a translator. Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved

13 Parts of an object module
module name, date, lengths list of public symbols and values in module list of external (extern) symbols used by module includes list of location of instructions that refer to these symbols code and constants this is the only part that is actually loaded and executed relocation dictionary end-of-module mark, checksum

14 Linker passes Pass 1: Pass 2: read all object modules
build table of module names and lengths build global symbol table of entry points and external references Pass 2: read all object modules (again) relocate their contents write all of them out to one file (executable file)

15 THE END skip and 7.4.4

16 Binding Time and Dynamic Relocation
The relocated binary program of Fig. 7-15(b) moved up 300 addresses. Many instructions now refer to an incorrect memory address. Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved

17 Dynamic Linking in MULTICS (1)
Before EARTH is called. Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved

18 Dynamic Linking in MULTICS (2)
After EARTH has been called and linked. Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved

19 Dynamic Linking in Windows
Use of a DLL file by two processes. Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved


Download ppt "The Assembly Language Level"

Similar presentations


Ads by Google