CS3350B Computer Architecture Winter 2015 Lecture 4

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

Goal: Write Programs in Assembly
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Instruction Set-Intro
CS/COE0447 Computer Organization & Assembly Language
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
1 ECE369 ECE369 Chapter 2. 2 ECE369 Instruction Set Architecture A very important abstraction –interface between hardware and low-level software –standardizes.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
ELEN 468 Advanced Logic Design
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2 Instructions: Language of the Computer
Chapter 2.
CS 300 – Lecture 10 Intro to Computer Architecture / Assembly Language Strings and Characters and More.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 4: Arithmetic / Data Transfer Instructions Partially adapted from Computer Organization.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
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.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
CS224 Fall 2011 Chap 2a Computer Organization CS224 Fall 2011 Chapter 2 a With thanks to M.J. Irwin, D. Patterson, and J. Hennessy for some lecture slide.
CSCI 136 Lab 1: 135 Review.
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Chapter 2 Instructions: Language of the Computer Part I.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /08/2013 Lecture 10: MIPS Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE.
CHAPTER 6 Instruction Set Architecture 12/7/
 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 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 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
CDA 3101 Spring 2016 Introduction to Computer Organization
Lecture 2: Instruction Set Architecture part 1 (Introduction) Mehran Rezaei.
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.
Computer Architecture & Operations I
Computer Architecture & Operations I
MIPS Assembly.
Instruction Set Architecture
Morgan Kaufmann Publishers
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
ECE3055 Computer Architecture and Operating Systems MIPS ISA
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
The University of Adelaide, School of Computer Science
Assembly Programming using MIPS R3000 CPU
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
The University of Adelaide, School of Computer Science
Systems Architecture Lecture 5: MIPS Instruction Set
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Chapter 2 Instructions: Language of the Computer
Computer Instructions
Computer Architecture
The University of Adelaide, School of Computer Science
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
Assembly Programming using MIPS R3000 CPU
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
Presentation transcript:

CS3350B Computer Architecture Winter 2015 Lecture 4 CS3350B Computer Architecture Winter 2015 Lecture 4.1: MIPS ISA: Introduction Marc Moreno Maza www.csd.uwo.ca/Courses/CS3350b [Adapted from lectures on Computer Organization and Design, Patterson & Hennessy, 5th edition, 2013]

Abstraction of Machine Structures Levels of representation I/O system Processor Compiler Operating System (Mac OSX) Application (ex: browser) Digital Design Circuit Design Instruction Set Architecture Datapath & Control Transistors Memory Hardware Software Assembler

The University of Adelaide, School of Computer Science 11 April 2017 Instructions: Language of the Computer Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 11 April 2017 Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects in common Early computers had very simple instruction sets Simplified implementation Many modern computers also have simple instruction sets Chapter 2 — Instructions: Language of the Computer

The MIPS Instruction Set The University of Adelaide, School of Computer Science 11 April 2017 The MIPS Instruction Set Used as the example throughout the book Stanford MIPS commercialized by MIPS Technologies (www.mips.com) Large share of embedded core market Applications in consumer electronics, network/storage equipment, cameras, printers, … Typical of many modern ISAs See MIPS Reference Data tear-out card, and Appendixes B and E Chapter 2 — Instructions: Language of the Computer

spim Assembler and Simulator spim is a simulator that runs MIPS32 assembly language programs It provides a simple assembler, debugger and a simple set of operating system services Interfaces: Spim, XSpim, PCSpim, QtSpim (new UI, cross-platform) See installation and user guide at http://pages.cs.wisc.edu/~larus/spim.html

Arithmetic Operations The University of Adelaide, School of Computer Science 11 April 2017 Arithmetic Operations Add and subtract, three operands Two sources and one destination add a, b, c # a gets b + c All arithmetic operations have this form Design Principle 1: Simplicity favors regularity Regularity makes implementation simpler Simplicity enables higher performance at lower cost Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 11 April 2017 Arithmetic Example C code: f = (g + h) - (i + j); Compiled MIPS code: add t0, g, h # temp t0 = g + h add t1, i, j # temp t1 = i + j sub f, t0, t1 # f = t0 - t1 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 11 April 2017 Register Operands Arithmetic instructions use register operands MIPS has a 32 × 32-bit register file Use for frequently accessed data Numbered 0 to 31 32-bit data called a “word” Assembler names $t0, $t1, …, $t9 for temporary values $s0, $s1, …, $s7 for saved variables Design Principle 2: Smaller is faster c.f. main memory: millions of locations Chapter 2 — Instructions: Language of the Computer

Register Operand Example The University of Adelaide, School of Computer Science 11 April 2017 Register Operand Example C code: f = (g + h) - (i + j); f, …, j in $s0, …, $s4 Compiled MIPS code: add $t0, $s1, $s2 add $t1, $s3, $s4 sub $s0, $t0, $t1 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 11 April 2017 Memory Operands Main memory used for composite data Arrays, structures, dynamic data To apply arithmetic operations Load values from memory into registers Store result from register to memory Memory is byte addressed Each address identifies an 8-bit byte Words are aligned in memory Address must be a multiple of 4 MIPS is Big Endian Most-significant byte at least address of a word c.f. Little Endian: least-significant byte at least address Chapter 2 — Instructions: Language of the Computer

Memory Operand Example 1 The University of Adelaide, School of Computer Science 11 April 2017 Memory Operand Example 1 C code: g = h + A[8]; g in $s1, h in $s2, base address of A in $s3 Compiled MIPS code: Index 8 requires offset of 32 4 bytes per word lw $t0, 32($s3) # load word add $s1, $s2, $t0 offset base register Chapter 2 — Instructions: Language of the Computer

Memory Operand Example 2 The University of Adelaide, School of Computer Science 11 April 2017 Memory Operand Example 2 C code: A[12] = h + A[8]; h in $s2, base address of A in $s3 Compiled MIPS code: Index 8 requires offset of 32 lw $t0, 32($s3) # load word add $t0, $s2, $t0 sw $t0, 48($s3) # store word Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 11 April 2017 Registers vs. Memory Registers are faster to access than memory Operating on memory data requires loads and stores More instructions to be executed Compiler must use registers for variables as much as possible Only spill to memory for less frequently used variables Register optimization is important! Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 11 April 2017 Immediate Operands Constant data specified in an instruction addi $s3, $s3, 4 No subtract immediate instruction Just use a negative constant addi $s2, $s1, -1 Design Principle 3: Make the common case fast Small constants are common Immediate operand avoids a load instruction Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 11 April 2017 The Constant Zero MIPS register 0 ($zero) is the constant 0 Cannot be overwritten Useful for common operations E.g., move between registers add $t2, $s1, $zero Chapter 2 — Instructions: Language of the Computer

Overview: MIPS R3000 ISA Instruction Categories Computational Load/Store Jump and Branch Floating Point coprocessor Memory Management Special Registers R0 - R31 PC HI LO OP rs rt rd sha funct immediate jump target 3 Basic Instruction Formats: all 32 bits wide R-format I-format J-format

MIPS Register Convention Name Register Number Usage Preserve on call? $zero constant 0 (hardware) n.a. $at 1 reserved for assembler $v0 - $v1 2-3 returned values no $a0 - $a3 4-7 arguments yes $t0 - $t7 8-15 temporaries $s0 - $s7 16-23 saved values $t8 - $t9 24-25 $k 26-27 Interrupt/trap handler $gp 28 global pointer $sp 29 stack pointer $fp 30 frame pointer $ra 31 return addr (hardware) Register Number Alternative Name Description 0 zero the value 0 1 $at (assembler temporary) reserved by the assembler 2-3 $v0 - $v1 (values) from expression evaluation and function results 4-7 $a0 - $a3 (arguments)First-four-parameters-for-subroutine. , Not preserved across procedure calls 8-15 $t0 - $t7 (temporaries) Caller saved if needed. Subroutines can use w/out saving. Not preserved across procedure calls 16-23 $s0 - $s7 (saved values) - Callee saved. A subroutine using one of these must save original and restore it before exiting. Preserved across procedure calls 24-25 $t8 - $t9 (temporaries) Caller saved if needed. Subroutines can use w/out saving. These are in addition to $t0 - $t7 above. Not preserved across procedure calls. 26-27 $k0 - $k1 reserved for use by the interrupt/trap handler 28 $gp global pointer. Points to the middle of the 64K block of memory in the static data segment. 29 $sp stack pointer Points to last location on the stack. 30 $s8/$fp saved value / frame pointer Preserved across procedure calls 31 $ra return address

MIPS ISA Selected Instruction Set Category Instr OP/funct Example Meaning Arithmetic add R 0/32 add $s1, $s2, $s3 $s1 = $s2 + $s3 subtract 0/34 sub $s1, $s2, $s3 $s1 = $s2 - $s3 add immediate I 8 addi $s1, $s2, 6 $s1 = $s2 + 6 or immediate 13 ori $s1, $s2, 6 $s1 = $s2 v 6 Data Transfer load word 35 lw $s1, 24($s2) $s1 = Memory($s2+24) store word 43 sw $s1, 24($s2) Memory($s2+24) = $s1 load byte 32 lb $s1, 25($s2) $s1 = Memory($s2+25) store byte 40 sb $s1, 25($s2) Memory($s2+25) = $s1 load upper imm 15 lui $s1, 6 $s1 = 6 * 216 Cond. Branch br on equal 4 beq $s1, $s2, L if ($s1==$s2) go to L br on not equal 5 bne $s1, $s2, L if ($s1 != $s2) go to L set on less than 0/42 slt $s1, $s2, $s3 if ($s2<$s3) $s1=1 else $s1=0 set on less than immediate 10 slti $s1, $s2, 6 if ($s2<6) $s1=1 else Uncond. Jump jump J 2 j 250 go to 1000 jump register 0/8 jr $t1 go to $t1 jump and link 3 jal 250 go to 1000; $ra=PC+4 similarity of the binary representation of related instructions simplifies the hardware design

Unsigned Binary Integers The University of Adelaide, School of Computer Science 11 April 2017 Unsigned Binary Integers Given an n-bit number Range: 0 to +2n – 1 Example 0000 0000 0000 0000 0000 0000 0000 10112 = 0 + … + 1×23 + 0×22 +1×21 +1×20 = 0 + … + 8 + 0 + 2 + 1 = 1110 Using 32 bits 0 to +4,294,967,295 Chapter 2 — Instructions: Language of the Computer

2s-Complement Signed Integers The University of Adelaide, School of Computer Science 11 April 2017 2s-Complement Signed Integers Given an n-bit number Range: –2n – 1 to +2n – 1 – 1 Example 1111 1111 1111 1111 1111 1111 1111 11002 = –1×231 + 1×230 + … + 1×22 +0×21 +0×20 = –2,147,483,648 + 2,147,483,644 = –410 Using 32 bits –2,147,483,648 to +2,147,483,647 Chapter 2 — Instructions: Language of the Computer

2s-Complement Signed Integers The University of Adelaide, School of Computer Science 11 April 2017 2s-Complement Signed Integers Bit 31 is sign bit 1 for negative numbers 0 for non-negative numbers –(–2n – 1) can’t be represented Non-negative numbers have the same unsigned and 2s-complement representation Some specific numbers 0: 0000 0000 … 0000 –1: 1111 1111 … 1111 Most-negative: 1000 0000 … 0000 Most-positive: 0111 1111 … 1111 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 11 April 2017 Signed Negation Complement and add 1 Complement means 1 → 0, 0 → 1 Example: negate +2 +2 = 0000 0000 … 00102 –2 = 1111 1111 … 11012 + 1 = 1111 1111 … 11102 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 11 April 2017 Sign Extension Representing a number using more bits Preserve the numeric value In MIPS instruction set addi: extend immediate value lb, lh: extend loaded byte/halfword beq, bne: extend the displacement Replicate the sign bit to the left c.f. unsigned values: extend with 0s Examples: 8-bit to 16-bit +2: 0000 0010 => 0000 0000 0000 0010 –2: 1111 1110 => 1111 1111 1111 1110 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 11 April 2017 Next Lecture: MIPS Instruction Representation Chapter 2 — Instructions: Language of the Computer