The Assembly Language Level

Slides:



Advertisements
Similar presentations
Assembly Code Example Selection Sort.
Advertisements

Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
The Assembly Language Level
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
3. Loaders & Linkers1 Chapter III: Loaders and Linkers Chapter goal: r To realize how a source program be loaded into memory m Loading m Relocation m Linking.
Chapter 3 Loaders and Linkers
Machine Independent Assembler Features
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Chapter 8: Programming the Microprocessor. Copyright ©2009 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved. The Intel.
COSC 120 Computer Programming
Loader- Machine Independent Loader Features
An introduction to systems programming
Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved The Operating System Machine.
The Assembly Language Level
Software Development Process Compiler Linker C File Asm. File Binary File Exec. File Assemble r Library Implementation Phase Debugger Profiler Verification.
Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved The Assembly Language Level.
Software Development and Software Loading in Embedded Systems.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
MIPS coding. SPIM Some links can be found such as:
The Assembly Language Level Part B – The Assembly Process.
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
Computer Science 101 How the Assembler Works. Assembly Language Programming.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Computer Science 210 Computer Organization More on Assembler.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
The Assembly Language Level Part C – Linking and Loading.
Security Attacks Tanenbaum & Bo, Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
CSc 453 Linking and Loading
Operating System Concepts and Techniques Lecture 9 Memory Management-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
Loaders and Linkers T 李俊葦. 1. Loader Accepts the object programs , prepares these programs for execution by the computer , and indicates the execution.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
1 CE 454 Computer Architecture Lecture 11 Ahmed Ezzat The Assembly Language Level, Ch-(7.1 – 7.4)
Compiling examples in MIPS
Lecture 3 Translation.
Topic 2: Hardware and Software
Assemblers, linkers, loaders
Computer Science 210 Computer Organization
Chapter 5- Assembling , Linking, and Executing Programs
System Programming and administration
Naming and Binding A computer system is merely a bunch of resources that are glued together with names Thus, much of system design is merely making choices.
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
Linking & Loading.
Memory Management © 2004, D. J. Foreman.
CS-3013 Operating Systems C-term 2008
Computer Science 210 Computer Organization
and Executing Programs
The Assembly Language Level
Loaders and Linkers: Features
The Instruction Set Architecture Level
Loaders and Linkers.
The Operating System Machine Level
Computer Organization and Design Assembly & Compilation
Linking & Loading CS-502 Operating Systems
Operating System Chapter 7. Memory Management
System Programming by Leland L. Beck Chapter 2
A programming language
Machine Independent Assembler Features
Chapter 6 Programming the basic computer
10/6: Lecture Topics C Brainteaser More on Procedure Call
Linking & Loading CS-502 Operating Systems
Machine Independent Assembler Features
An introduction to systems programming
Program Assembly.
Presentation transcript:

The Assembly Language Level Part C – Linking and Loading

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?

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. 0-13-148521-0

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.

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. 0-13-148521-0

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. 0-13-148521-0

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

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.

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 400 100 B 600 500 C 500 1100 D 300 1600

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. 7-14 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. 0-13-148521-0

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. 0-13-148521-0

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. 0-13-148521-0

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

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)

THE END skip 7.4.3 and 7.4.4

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. 0-13-148521-0

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

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. 0-13-148521-0

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. 0-13-148521-0