Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
Chapter 2 — Instructions: Language of the Computer — 1 Branching Far Away If branch target is too far to encode with 16-bit offset, assembler rewrites.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 8 Sept 23 Completion of Ch 2 translating procedure into MIPS role of compilers, assemblers, linking, loading etc. pitfalls, conclusions Chapter.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2 Instructions: Language of the Computer
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
The University of Adelaide, School of Computer Science
CS3350B Computer Architecture Winter 2015 Lecture 4
Lecture 8: MIPS Instruction Set
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.
Assembly Language II CPSC 321 Andreas Klappenecker.
14:332:331 Computer Architecture and Assembly Language Spring 06 Week 4: Addressing Mode, Assembler, Linker [Adapted from Dave Patterson’s UCB CS152 slides.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
RISC Concepts, MIPS ISA and the Mini–MIPS project
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
CS 61C L14Introduction to MIPS: Instruction Representation II (1) Garcia, Spring 2004 © UCB Roy Wang inst.eecs.berkeley.edu/~cs61c-tf inst.eecs.berkeley.edu/~cs61c.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
Mohamed Younis CMCS 411, Computer Architecture 1 CMCS Computer Architecture Lecture 5 Addressing Mode & Architectural Design Guidelines February.
June 18, 2001Systems Architecture II1 Systems Architecture II Systems Architecture I Review * Jeremy R. Johnson June 18, 2001 * Most figures from Computer.
CS35101 Computer Architecture Spring 2006 Week 5 Paul Durand ( Course url:
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
1  1998 Morgan Kaufmann Publishers Machine Instructions: Language of the Machine Lowest level of programming, control directly the hardware Assembly instructions.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Lecture 4: MIPS Instruction Set
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
Oct. 25, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Alternative Instruction Sets * Jeremy R. Johnson Wed. Oct. 25, 2000.
Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; Solutions? Why not? put 'typical constants' in memory.
CMPE 325 Computer Architecture II
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
EE472 – Spring 2007P. Chiang, with Slide Help from C. Kozyrakis (Stanford) ECE472 Computer Architecture Lecture #3—Oct. 2, 2007 Patrick Chiang TA: Kang-Min.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3.
Instruction Set Architecture Chapter 3 – P & H. Introduction Instruction set architecture interface between programmer and CPU Good ISA makes program.
Lecture 16: 10/29/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 14, 15 Addressing Mode.
Chapter 2 Instructions: Language of the Computer.
Computer Architecture & Operations I
Computer Architecture Instruction Set Architecture
Instruction Sets Chapter 2
Computer Architecture Instruction Set Architecture
The University of Adelaide, School of Computer Science
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Systems Architecture Lecture 5: MIPS Instruction Set
Henk Corporaal TUEindhoven 2010
MIPS Instructions.
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
The University of Adelaide, School of Computer Science
Instruction encoding The ISA defines Format = Encoding
Computer Organization and Design Assembly & Compilation
Computer Architecture
10/6: Lecture Topics C Brainteaser More on Procedure Call
Program Assembly.
Presentation transcript:

Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all figures from Computer Organization and Design: The Hardware/Software Approach, Third Edition, by David Patterson and John Hennessy, are copyrighted material (COPYRIGHT 2004 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED).

Lec 9Systems Architecture2 Introduction Objective: To review the MIPS instruction set and encoding. Objective: To learn how the MIPS assembler, linker, and loader work. Topics –Immediate instructions –Addressing in branches and jumps –Review MIPS instruction set and addressing modes –Instruction formats and encoding –Assembler –Linker and object files –Loader and executable files

Lec 9Systems Architecture3 MIPS Instruction Set Arithmetic/Logical –add, sub, and, or –addi, andi, ori Data Transfer –lw, lb –sw, sb –lui Control –beq, bne –slt, slti –j, jal, jr

1 May 2015Chapter 2 — Instructions: Language of the Computer 4 Assembler Pseudoinstructions Most assembler instructions represent machine instructions one-to-one Pseudoinstructions: figments of the assembler’s imagination move $t0, $t1 → add $t0, $zero, $t1 blt $t0, $t1, L → slt $at, $t0, $t1 bne $at, $zero, L –$at (register 1): assembler temporary

Lec 9Systems Architecture5 Small constants are used frequently (~50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; Solution: use immediate format and hardwired registers –store / imbed constants in the low order 16-bits. –create hard-wired registers (like $zero) for constants. Design Principle: Make the common case fast. –Memory access can be x slower than accessing registers –Remove memory load delay / overhead –Store the constant in the instruction itself Immediate Addressing – Why?

Lec 9Systems Architecture6 MIPS Instruction Examples addi $29, $29, 4 slti $8, $18, 10 andi $29, $29, 6 ori $29, $29, 4 I-Format machine code Example: addi $s0, $s0, 4 Immediate Addressing 816 4

Lec 9Systems Architecture7 How about larger constants? Since MIPS only allows 16-bit constants (a common case) Two instructions are required to imbed a 32-bit constant li $s0, 0x003c0900 will be translated by the assembler to –lui $s0, 0x003c; load upper immediate instruction –ori $s0, $s0, 0x0900 When constructing 32 bit offsets for memory addresses the MIPS assembler uses the $at register for temporary space $at stands for “assembler temporary” register

Lec 9Systems Architecture8 Loading a 32-bit Constant “load upper immediate instruction” lui places its 16-bit constant in the upper bit space lui $t0, Use ori (or immediate) to place the lower 15-0 bit space: ori $t0, $t0, lui ori result

Lec 9Systems Architecture9 Assembly provides convenient symbolic representation –“Mnemonics” are much easier than writing down numbers –Uniform feel to the instructions that hides machine code Machine language is the underlying reality –E.g., destination is no longer first –Difficult for human to use: time-consuming and error-prone Assembly can provide 'pseudoinstructions' –move, bgt, blt, etc. exist only in assembly code –Pseudoinstructions are translated to real instructions. When considering performance count the real instructions! Assembly Language vs. Machine Language

Lec 9Systems Architecture10 Simple instructions all 32 bits wide Well-organized and structured, no unnecessary baggage Only three instruction formats Overview of MIPS

Lec 9Systems Architecture11 Instructions: bne $t4,$t5,Label Next instruction is at Label if $t4≠$t5 beq $t4,$t5,Label Next instruction is at Label if $t4=$t5 I-Format : How to construct the branch target address: use PC+4 and add the (signed) value of immediate constant to it. This works because most branches are local, -- the target address is near by (principle of locality). Note: branches are restricted to 2 17 byte “distance” jumps. op rs rt 16 bit address I PC-relative Addressing in Branches

Lec 9Systems Architecture13 Pseudodirect Addressing in Jumps J-Format: Jump instructions use 28 high order bits of PC –Jumps are restricted to 2 28 byte jumps (256 MB) 32-bit address construction: –Take bits of PC+4 –Concatenate them to 26-bit constant (forms bits 27-2) –Append “00” to the “end” (bits 1-0) to reconstruct the byte address 6-bits 26-bit constant PC+4[31-28] 26-bit constant from j instruction

Lec 9Systems Architecture14 MIPS Encoding All instructions are 32-bits long Opcode is always in the high-order 6 bits Only three instruction formats 32 registers implies 5 bit register addresses: –$zero R0 ; zero register always equal to 0 –$at R1 ; temporary register (assembler temporary) –$v0 - $v1 R2-R3 ; return registers –$a0 - $a3 R4-R7 ; argument registers –$t0 - $t7 R8-R15 ; temporary - not preserved across calls –$s0 - $s7 R16-R23 ; saved registers - preserved across calls –$t8 - $t9 R24-R25 ; temporary not preserved across calls –$k0 - $k1 R26-R27 ; reserved by OS kernel –$gp R28 ; global pointer –$sp R29 ; stack pointer –$fp R30 ; frame pointer –$ra R31 ; return address

Lec 9Systems Architecture15 MIPS Addressing Modes Immediate Addressing –16 bit constant from low order bits of instruction –addi $t0, $s0, 4 Register Addressing –add $t0, $s0, $s1 Base Addressing (displacement addressing) –16-bit constant from low order bits of instruction plus base register –lw $t0, 16($sp) PC-Relative Addressing –(PC+4) + 16-bit address (word) from instruction –bne $s0, $s1, Target Pseudodirect Addressing –high order 4 bits of PC+4 concatenated with 26 bit word address - low order 26 bits from instruction shifted 2 bits to the left –j Address

Lec 9Systems Architecture16 Decoding Machine Code Example:

Lec 9Systems Architecture17 Design Principles Simplicity favors regularity –uniform instruction length –all ALU operations have 3 register operands –register addresses in the same location for all instruction formats Smaller is faster –register architecture –small number of registers Good design demands good compromises –fixed length instructions and only 16 bit constants –several instruction formats but consistent length Make common cases fast –immediate addressing –16 bit constants –only beq and bne

Lec 9Systems Architecture18 Translation Hierarchy

Lec 9Systems Architecture19 Assembler Translates assembly code to machine code Creates object file Symbolic labels to addresses Pseudoinstructions (move, la, li, blt, bgt,...) Assembly directives (.text,.globl,.space,.byte,.asciiz,...) Loading a 32-bit constant (lui and ori) Constructing 32-bit addresses (use $at) Branching far away (beq $s0, $s1, L1 => bne and j)

1 May 2015Chapter 2 — Instructions: Language of the Computer 20 Producing an Object Module Assembler (or compiler) translates program into machine instructions Provides information for building a complete program from the pieces –Header: described contents of object module –Text segment: translated instructions –Static data segment: data allocated for the life of the program –Relocation info: for contents that depend on absolute location of loaded program –Symbol table: global definitions and external refs –Debug info: for associating with source code

Lec 9Systems Architecture21 Format of Object File Object file header (size and position) Text segment (instructions - machine code) Data segment (data that comes with the program, both static and dynamic) Relocation information (instructions and data words that depend on absolute addresses when program is loaded into memory) Symbol table (external references) Debugging information

Lec 9Systems Architecture22 Linker Place code and data modules symbolically in memory Determine the addresses of data and instruction labels Patch both the internal and external references

1 May 2015Chapter 2 — Instructions: Language of the Computer 23 Linking Object Modules Produces an executable image 1.Merges segments 2.Resolve labels (determine their addresses) 3.Patch location-dependent and external refs Could leave location dependencies for fixing by a relocating loader –But with virtual memory, no need to do this –Program can be loaded into absolute location in virtual memory space

1 May 2015Chapter 2 — Instructions: Language of the Computer 24 Dynamic Linking Only link/load library procedure when it is called –Requires procedure code to be relocatable –Avoids image bloat caused by static linking of all (transitively) referenced libraries –Automatically picks up new library versions

1 May 2015Chapter 2 — Instructions: Language of the Computer 25 Lazy Linkage Indirection table Stub: Loads routine ID, Jump to linker/loader Linker/loader code Dynamically mapped code

Lec 9Systems Architecture26 MIPS Memory Convention

Lec 9Systems Architecture27 Loader Read executable file header to determine size of text and data segments Creates an address space large enough for the text and data Copies instructions and data from executable file into memory Copies parameters (if any) to the main program onto the stack Initializes the machine registers and sets stack pointer to first free location Jumps to a start-up routine that copies the parameters into the argument registers and calls the main routine of the program. When the main routine returns, the start-up routine terminates the program with an exit system call.

1 May 2015Chapter 2 — Instructions: Language of the Computer 28 Loading a Program Load from image file on disk into memory 1.Read header to determine segment sizes 2.Create virtual address space 3.Copy text and initialized data into memory Or set page table entries so they can be faulted in 4.Set up arguments on stack 5.Initialize registers (including $sp, $fp, $gp) 6.Jump to startup routine Copies arguments to $a0, … and calls main When main returns, do exit syscall

1 May 2015Chapter 2 — Instructions: Language of the Computer 29 Starting Java Applications Simple portable instruction set for the JVM Interprets bytecodes Compiles bytecodes of “hot” methods into native code for host machine

Lec 9Systems Architecture30 Linking Example

Lec 9Systems Architecture31 Resulting Executable File