April 23, 2001Systems Architecture I1 Systems Architecture I (CS 281-001) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,

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.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
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.
ELEN 468 Advanced Logic Design
CS3350B Computer Architecture Winter 2015 Lecture 4
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2 Instructions: Language of the Computer
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
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
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
CS3350B Computer Architecture Winter 2015 Lecture 4
Lecture 8: MIPS Instruction Set
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
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.
MIPS Architecture CPSC 321 Computer Architecture Andreas Klappenecker.
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
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.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
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,
Lecture 4: MIPS Instruction Set
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
Oct. 25, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Alternative Instruction Sets * Jeremy R. Johnson Wed. Oct. 25, 2000.
CMPE 325 Computer Architecture II
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
Chapter 2 Instructions: Language of the Computer.
MIPS Assembly.
Computer Architecture & Operations I
Computer Architecture Instruction Set Architecture
Instruction Sets Chapter 2
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
CS170 Computer Organization and Architecture I
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Systems Architecture Lecture 5: MIPS Instruction Set
Henk Corporaal TUEindhoven 2010
MIPS Instructions.
MIPS Instruction Encoding
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
MIPS Instruction Encoding
Instruction encoding The ISA defines Format = Encoding
Lecture 5: Procedure Calls
Lecture 6: Assembly Programs
MIPS Coding Continued.
Computer Architecture
Program Assembly.
Presentation transcript:

April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23, 2001 *This lecture was derived from material in the text (sec ). All figures from Computer Organization and Design: The Hardware/Software Approach, Second Edition, by David Patterson and John Hennessy, are copyrighted material (COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED).

April 23, 2001Systems Architecture I2 Introduction Objective: To learn how the MIPS assembler, linker, and loader work. To review the MIPS instruction set and encoding. 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

April 23, 2001Systems Architecture I3 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

April 23, 2001Systems Architecture I4 Immediate Addressing Many arithmetic operations involve small constants Example: (offset of 4 from stack pointer) –lw $t0, AddressofConstant4($zero) –add $sp, $sp, $t0 Remove overhead of extra load by storing constant in the instruction itself I-format instructions store a constant in the low order 16-bits Example: –addi $sp, $sp,

April 23, 2001Systems Architecture I5 Loading a 32-Bit Constant Since MIPS only allows 16-bit constants (common case) Two instructions are required to create a 32-bit constant li $s0, 0x003c0900 –lui $s0, 0x003c; load upper immediate instruction –ori $s0, $s0, 0x0900 Book uses addi, but this doesn’t work in general due to negative numbers When constructing 32 bit offsets for memory addresses the MIPS assembler uses the $at register for temporary space

April 23, 2001Systems Architecture I6 Addressing in Branches and Jumps J-Format instructions Example: j Branches require 2 register addresses  Use I-Format with 16-bit constant This implies that programs be restricted to 2 16 bytes, which is unacceptable. However, branches are typically to addresses near the current address PC-relative addressing –address computed relative to PC bits26-bits

April 23, 2001Systems Architecture I7 Branch Examples Bne $s0, $s1, Exit ; goto Exit if $s0  $s1 Since instruction address are word aligned, branch address is treated as a word address (two extra bits) Branches to addresses more than  2 15 words away must use two instructions Example: –beq $s0, $s1, FarAway –bne $s0, $s1, next –j FarAway –next: Exit 16-bits

April 23, 2001Systems Architecture I8 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 –$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

April 23, 2001Systems Architecture I9 MIPS Instruction Formats R format (register format - add, sub, …) I format (immediate format - lw, sw, …) Example: lw $s1, 100($s2) Example: add$t0, $s0, $s1 op rs rt rd shamt func op rs rt address

April 23, 2001Systems Architecture I10 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

April 23, 2001Systems Architecture I11 Example Loop: add $t1, $s3, $s3 add $t1, $t1, $t1 add $t1, $t1, $s6 lw $t0, 0($t1) bne $t0, $s5, Exit add $s3, $s3, $s4 j Loop Exit:

April 23, 2001Systems Architecture I12 Decoding Machine Code Example:

April 23, 2001Systems Architecture I13 Design Principles Simplicity favors regularity Smaller is faster Good design demands good compromises Make common cases fast

April 23, 2001Systems Architecture I14 Translation Hierarchy

April 23, 2001Systems Architecture I15 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)

April 23, 2001Systems Architecture I16 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

April 23, 2001Systems Architecture I17 Linker Place code and data modules symbolically in memory Determine the addresses of data and instruction labels Patch both the internal and external references

April 23, 2001Systems Architecture I18 MIPS Memory Convention

April 23, 2001Systems Architecture I19 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.

April 23, 2001Systems Architecture I20 Linking Example

April 23, 2001Systems Architecture I21 Resulting Executable File