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.

Slides:



Advertisements
Similar presentations
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
Advertisements

Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
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
Computer Organization CS224 Fall 2012 Lesson 12. Synchronization  Two processors or threads sharing an area of memory l P1 writes, then P2 reads l Data.
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++
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
System Programming Mr. M. V. Nikum (B.E.I.T). Introduction What is System? System is the collection of various components Ex:- College is a system What.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Assembly.
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I.
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
CS2422 Assembly Language & System Programming December 22, 2005.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
An introduction to systems programming
The Assembly Language Level
Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved The Assembly Language Level.
4-1 Chapter 4 - The Instruction Set Architecture Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
A Simple Two-Pass Assembler
MIPS coding. SPIM Some links can be found such as:
4-1 Chapter 4 - The Instruction Set Architecture Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of.
ITEC 352 Lecture 20 JVM Intro. Functions + Assembly Review Questions? Project due today Activation record –How is it used?
Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
5-1 Chapter 5 - Languages and the Machine Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of Computer.
EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014.
4-1 Chapter 4 - The Instruction Set Architecture Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
6-1 Chapter 6 - Languages and the Machine Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer.
Assemblers.
Chapter 1 Computer architecture Languages: machine, assembly, high
Languages and the Machine Chapter 5 CS221. Topics The Compilation Process The Assembly Process Linking and Loading Macros We will skip –Case Study: Extensions.
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
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.
4-1 Chapter 4 - The Instruction Set Architecture Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
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.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
9/20/6Lecture 2 - Prog Model Architecture, Data Types and Addressing Modes.
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
Instruction Sets: Addressing modes and Formats Group #4  Eloy Reyes  Rafael Arevalo  Julio Hernandez  Humood Aljassar Computer Design EEL 4709c Prof:
The Assembly Language Level Part C – Linking and Loading.
LINKERS Execution of a program written in a language L involves the following steps: 1.Translation of the program: Performed by the translator for language.
The Assembly Process Computer Organization and Assembly Language: Module 10.
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.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
Lecture 3 Translation.
Computer Architecture & Operations I
Computer Science 210 Computer Organization
System Programming and administration
Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 4 – The Instruction Set Architecture.
Assembler Design Options
Computer Science 210 Computer Organization
The Assembly Language Level
68000 Architecture, Data Types and Addressing Modes
Computer Organization and Design Assembly & Compilation
The Assembly Language Level
A Simple Two-Pass Assembler
Computer Architecture
Loaders and Linkers.
Chapter 1 Computer architecture Languages: machine, assembly, high
10/6: Lecture Topics C Brainteaser More on Procedure Call
An introduction to systems programming
Presentation transcript:

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 of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 5: Languages and the Machine

5-2 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Topics 5.2 The Assembly Process 5.3 Linking and Loading 5.4 Macros Linker exe file Prog1 (MC) prog2 (MC) prog n (MC) … LoaderMemory Assembler Assembly lan. progsMachine code libs

5-3 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring The Assembly Process The process of translating an assembly language program into a machine language program is referred to as the assembly process. Assemblers generally provide this support: — Allow programmer to specify locations of data and code. — Provide assembly-language mnemonics for all machine instructions and addressing modes, and translate valid assembly language statements into the equivalent machine language. — Permit symbolic labels to represent addresses and constants. — Provide a means for the programmer to specify the starting address of the program, if there is one; and provide a degree of assemble-time arithmetic. — Include a mechanism that allows variables to be defined in one assembly language program and used in another, separately assembled program. — Support macro expansion.

5-4 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Assembly Example We explore how the assembly process proceeds by “hand assembling” a simple ARC assembly language program.

5-5 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Macro Definition for PUSH

5-6 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Macro expansion for PUSH PUSH %r2 PUSH %r3 PUSH %r1 MACRO definition …

5-7 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Instruc- tion For- mats and PSR Format for the ARC

5-8 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Assembled Code ld [x], %r ld [y], %r addcc %r1,%r2,%r st %r3, [z] jmpl %r15+4, %r

5-9 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring 2-PASS Assembler Goes over the program twice 1 st pass: Find out addresses for all DATA items and machine instructions Employing location counter and forward referencing Keep track of the addresses of the current instruction or data items as assembly proceeds Create a symbolic table Translate each assembly instruction into machine instruction Mnemonics Addressing modes Has not generated machine code yet. Location counter (similar to PC) Initialized to what.org specifies/zero Incremented by the size of each instruction

5-10 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Address for each instruction

5-11 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Symbol table Contains all labels and constant values in the assembly program After the first pass, the assembly will have identified and entered all symbols into the symbolic table during the second pass, the assembler generates the machine code, inserting the values of symbols, which are known

5-12 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Symbol table Symbol table for example 1: main2048 x2068 y2072 z2076

5-13 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

5-14 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Symbol table Symbol value a_start3000 length -- address -- loop2060 done2088

5-15 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Symbol table cont’d Symbol value a_start3000 length 2092 (1) address 2096 (2) loop2060 done2088

5-16 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Assembled Program

5-17 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Second pass After the symbol table is created the program is read a second time Start from.begin Machine code is generated using symbol table

5-18 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Final tasks of the assembler Extra info to be added to the program for the linker and loader Linker: linking modules together Loader: putting the program into memory Module name and size Memory and segment info, such as code, data, stack The address of start symbol (if defined) The info about global and external symbols The address of any global symbols Info about any library routines that are referenced by the module The value of any constants to be loaded to memory Some loaders expect data initialization to be specified separately from the binary code Relocation info

5-19 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Relocation info Linker will link all the modules by concatenating them To do so some of the modules need to be relocated Example:

5-20 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Location of programs in memory As long as program is in user-accessible segment Might not in the address indicated by.org Modules are concatenated one after the other After linking, some modules are relocated to other addresses Most of addresses we use are re-locatable Exception: fixed addresses (I/O devices)

5-21 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

5-22 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Linking and loading A number of separately compiled/assembled modules Linker: a software program Combines separately assembled programs (object modules) into a single program (load module/exe) Loader: a software program that places the load module into main memory Load the various memory segments with the appropriate values and initialize certain registers (i.e. %sp, %pc)

5-23 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring linking Resolve address refs that are external to modules as it links them Relocate each module in order to combine them Specify the starting symbol of the load module Identify different memory segments Needs to know local symbol names from global symbol names Only address labels can be global or external Some addresses can not be relocated External symbols defined in another module Absolute numbers (defined by pseudo-code) ONE.equ1 a_start.equ 3000 Content of the address when relocated, do not change i.e : x :105 !relocate x, address changes, but content remains the same

5-24 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Linking: Using.global and.extern A.global is used in the module where a symbol is defined and a.extern is used in every other module that refers to it.

5-25 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Linking and Loading: Symbol Tables Symbol tables for the previous example:

5-26 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring loading Relocating loader More than one modules, relocate by adding an offset to all re- locatable code in that module Linking loader Does both linking and loading header info An exe file contains a header (inserted by linker) Where to load the program Starting address Relocation info What routines are available externally Dll (microsoft)

5-27 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Example ARC Program

5-28 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Recursive Macro Expansion