COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 5 Unsigned integer and floating point.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Spring 2013 Advising Starts this week! CS2710 Computer Organization1.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
Chapter Three.
Computer Organization CS224 Fall 2012 Lesson 19. Floating-Point Example  What number is represented by the single-precision float …00 
05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department.
Arithmetic in Computers Chapter 4 Arithmetic in Computers2 Outline Data representation integers Unsigned integers Signed integers Floating-points.
CSCE 212 Chapter 3: Arithmetic for Computers Instructor: Jason D. Bakos.
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
Lecture 16: Computer Arithmetic Today’s topic –Floating point numbers –IEEE 754 representations –FP arithmetic Reminder –HW 4 due Monday 1.
Computer Arithmetic : Floating- point CS 3339 Lecture 5 Apan Qasem Texas State University Spring 2015 *some slides adopted from P&H.
1 Lecture 9: Floating Point Today’s topics:  Division  IEEE 754 representations  FP arithmetic Reminder: assignment 4 will be posted later today.
1 Ó1998 Morgan Kaufmann Publishers Chapter 4 計算機算數.
Computer Systems Organization: Lecture 3
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 11: Floating Point Partially adapted from Computer Organization and Design, 4 th edition,
Fall 2003SYCS-401 Operating Systems Instruction Set Architecture An overview of MIPS R3000 assembly language.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Systems Architecture Lecture 14: Floating Point Arithmetic
Arithmetic for Computers
Ellen Spertus MCS 111 October 11, 2001 Floating Point Arithmetic.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /14/2013 Lecture 16: Floating Point Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Lecture 9: Floating Point
Floating Point Representation for non-integral numbers – Including very small and very large numbers Like scientific notation – –2.34 × –
In Class Execise. .data A:.word 0,1,2,3,4,5,6,7,8,9.text.globl main main: la $a0,A li $a1,6 li $a2,5 jal onUpStream done: li $v0, 10# exit syscall onUpStream:
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
CDA 3101 Fall 2013 Introduction to Computer Organization
CSCI 6307 Foundation of Systems Review: Midterm Exam Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Restoring Unsigned Integer Division
1 Lecture 10: Floating Point, Digital Design Today’s topics:  FP arithmetic  Intro to Boolean functions.
MIPS mul div, and MIPS floating point instructions.
C OMPUTER O RGANIZATION AND D ESIGN The Hardware/Software Interface 5 th Edition Chapter 3 Arithmetic for Computers.
CS 224 Computer Organization Spring 2011 Arithmetic for Computers With thanks to M.J. Irwin, D. Patterson, and J. Hennessy for some lecture slide contents.
Floating Point Numbers Opening Discussion zWhat did we talk about last class? zHave you seen anything interesting in the news?
CHAPTER 3 Arithmetic For Computers 1/31/ Topics for discussion 1/31/ Number system: { radix/base, a set of distinct digits, operations} Radix.
CSE 340 Simulation Modeling | MUSHFIQUR ROUF CSE340:
Morgan Kaufmann Publishers Dr. Zhao Zhang Iowa State University
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral.
COMPUTER ORGANIZATION ARITHMETIC YASSER MOHAMMAD.
CSE 340 Computer Architecture Spring 2016 MIPS Arithmetic Review.
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
/ Computer Architecture and Design
Morgan Kaufmann Publishers Arithmetic for Computers
Computer Architecture & Operations I
Data Representation Binary Numbers Binary Addition
Arithmetic for Computers
Chapter Three : Arithmetic for Computers
CS/COE0447 Computer Organization & Assembly Language
/ Computer Architecture and Design
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Lecture 10: Floating Point, Digital Design
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
MPIS Instructions Functionalities of instructions Instruction format
ECE232: Hardware Organization and Design
Instruction encoding The ISA defines Format = Encoding
Review.
October 24 Programming problems? Read Section 6.1 for November 5
October 17 Chapter 4 – Floating Point Read 5.1 through 5.3 1/16/2019
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
March 27 Test 2 Review Read Sections 5.1 through 5.3.
Digital System Design II 数字系统设计2
Chapter 3 Arithmetic for Computers
MIPS Assembly.
Chapter 3 Arithmetic for Computers
COMS 361 Computer Organization
Number Representation
Presentation transcript:

COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 5 Unsigned integer and floating point instructions Topics: 1. Unsigned instructions 2. Floating Point: IEEE 754 single and double precision formats 3. Floating Point Registers and Instructions Patterson: Sections 3.1 – 3.2, 3.5

2 Unsigned and Signed Arithmetic MIPS has a separate format for unsigned and signed integers 1.Unsigned integers — are saved as 32-bit words — Example:Smallest unsigned integer is hex = 0 ten Largest unsigned integer is ffffffff hex = 4,294,967,295 ten 2.Signed integers — are saved as 32-bit words in 2’s complement with the MSB reserved for sign — If MSB = 1, then the number is negative — If MSB = 0, then the number is positive — Example: Smallest signed integer: two =  (2 31 ) 10 =  2,147,483, Largest signed integer: two = (2 31  1) 10 = 2,147,483,647 10

3 MIPS Commands for Unsigned Numbers CategoryInstructionExampleMeaningComments Arithmetic add(u) add $s1,$s2,$s3$s1 ← $s2+$s3 Most arithmetic Subtract(u) sub $s1,$s2,$s3$s1 ← $s2-$s3 instruction have addi(u) add $s1,$s2,100$s1 ← $s2+100 unsigned format Data Transfer load word lw $s1,100($s2)$s1 ← Mem[$s2+100] store word lw $s1,100($s2)Mem[$s2+100] ← $s1 load byte unsigned lbu $s1,100($s2)$s1 ← Mem[$s2+100] Unsigned store byte sb $s1,100($s2)Mem[$s2+100] ← $s1 1 byte only Conditional branch branch on equal beq $s1,$s2,Lif($s1==$s2) go to L branch not equal bne $s1,$s2,Lif($s1!=$s2) go to L set on less than slt $s1,$s2,$s3 if($s2<$s3) $s1 = 1 else $s1 = 0 set on less than immediate slti $s1,$s2,10 if($s2<10) $s1 = 1 else $s1 = 0 set less than unsigned sltu $s1,$s2,$s3- same as slt - Unsigned slt unsign immediate sltui $s1,$s2,100- same as slti - Unsigned Unconditional jump jump j 2500go to (4 x 2500) jump register jr $rago to $t1 jump and link jal fact go to fact; set $ra = PC + 4

4 Addition and Subtraction In MIPS, addition and subtraction for signed numbers use 2’s complement arithmetic Example 1: Add 10 ten and 15 ten Step 1: Represent the operands in 2’s complelement 10 ten = two 15 ten = two Step 2: Perform bit by bit addition using table ten + 15 ten = two = 25 ten Example 2: Subtract 15 ten from 10 ten The problem is reduced to (10 ten + (  15 ten )) 10 ten = two  15 ten = two 10 ten  15 ten = two =  5 ten Table 1: Truth Table for addition

5 Overflow (1) Recall that: Smallest signed integer: two =  (2 31 ) ten =  2,147,483,648 ten Largest signed integer: two = (2 31  1) ten = 2,147,483,647 ten What happens if the result of an operation is more than the largest signed integer or less than the smallest signed integer? Example: Add 2,147,483,640 ten and 28 ten 28 ten = two 2,147,483,640 ten = two 28 ten + 2,147,483,640 ten = two =  2,147,483,628 ten Overflow caused the value to be perceived as a negative integer

6 Overflow (2) When can overflow occur? OperationOperand AOperand B Result indicating overflow A + BA >= 0B >= 0< 0 A + BA < 0B < 0>= 0 A  B A >= 0B < 0< 0 A  BA < 0B >= 0>= 0

7 Floating Point: Single Precision 1.In MIPS, decimal numbers are represented with the IEEE 754 binary representation that uses the normalized standard scientific binary notation defined as 2.A number in normalized scientific notation has a mantissa that has no leading 0’s and must be of the form (1 + fraction). For example, the binary representations 2.0 × 2  5, 0.5 × 2  3, 4.0 × 2  6, and 1.0 × 2  4 are all equivalent but only 1.0 × 2  4 is the normalized scientific binary notation. 3.MIPS allows for two floating point representations: Single precision and double precision. 4.Single precision has a bias of 127 while double precision has a bias of In single precision, the floating point representation is 32 bit long and has the following form where S represents the sign bit, which is 1 for negative numbers and 0 for positive numbers. Activity 2: Represent  0.75 ten in single precision of IEEE 754 binary representation Sexponentfraction (8 bits)(23 bits)

8 Floating Point: Double Precision 1.In double precision, the value of bias in is In single precision, the floating point representation is 64 bit long and has the following form Activity 3: Represent  0.75 ten in double precision of IEEE 754 binary representation. Activity 4: Show that the largest magnitude that can be represented using single precision is ±2.0 ten × 10 38, while the smallest fraction that can be represented is ±2.0 ten × 10  Sexponentfraction (11 bits)(Total of 52 bits) fraction (continued)

9 Floating Point Registers NameExampleComments 32 floating point registers each is 32 bits long $f0,$f1,$f2,$f3,$f4,…,$f31 MIPS floating point registers are used in pairs for double precision numbers Memory w/ 2 30 words Memory[0], Memory[4], … Memory[ ] Memory is accessed one floating point (single or double precision) at a time The following is the established register usage convention for the floating point registers: $f0,$f1,$f2,$f3: Function-returned values $f4,$f5,…, $f11: Temporary values $f12,$f13,$f14,$f15: Arguments passed into a function $f16,$f17,$f18,$f19: More Temporary values $f20,$f21,…, $f31: Saved values

10 CategoryInstructionExampleMeaningComments Arithmetic FP add single add.s $f2,$f4,$f6$f2 ← $f4+$f6 Single Prec. FP subtract single sub.s $f2,$f4,$f6$f2 ← $f4-$f6 Single Prec. FP multiply single mul.s $f2,$f4,$f6 $f2 ← $f4 × $f6 Single Prec. FP divide single div.s $f2,$f4,$f6 $f2 ← $f4 / $f6 Single Prec. FP add double add.d $f2,$f4,$f6$f2 ← $f4+$f6 Double Prec. FP subtract double sub.d $f2,$f4,$f6$f2 ← $f4-$f6 Double Prec. FP multiply double mul.d $f2,$f4,$f6 $f2 ← $f4 × $f6 Double Prec. FP divide double div.d $f2,$f4,$f6 $f2 ← $f4 / $f6 Double Prec. Data Transfer load word copr.1 lwc1 $f2,100($s2)$f2 ← Mem[$s2+100] Single Prec. store word copr.1 swc1 $f2,100($s2)Mem[$s2+100] ← $f2 Single Prec. Conditional branch FP compare single (eq, ne, lt, le, gt, ge) c.lt.s $f2,$f4 if($f2<$f4)cond = 1, else cond = 0 Single Prec. FP compare double (eq, ne, lt, le, gt, ge) c.lt.d $f2,$f4 if($f2<$f4)cond = 1, else cond = 0 Double Prec. Branch on FP true bc1t 25 if cond==1 go to PC Single/ Double Prec. Branch on FP false bc1f 25 if cond==0 go to PC Single/ Double Prec. Floating Point Instructions

11 Example # calculate area of a circle.data Ans:.asciiz"The area of the circle is: " Ans_add:.word Ans# Pointer to String (Ans) Pi:.double Rad:.double Rad_add:.word Rad# Pointer to float (Rad).text main:lw $a0, Ans_add($0) # load address of Ans into $a0 addi $v0, $0, 4# Sys Call 4 (Print String) syscall # # load float (Assembler Instruction) la $s0, Pi# load address of Pi into $s0 ldc1 $f2, 0($s0)# $f2 = Pi # # load float (MIPS Instruction) lw $s0, Rad_add($0)# load address of Rad into $s0 ldc1 $f4, 0($s0)# $f4 = Rad mul.d $f12, $f4, $f4 mul.d $f12, $f12, $f2 addi $v0, $0, 3# Sys Call 3 (Print Double) syscall exit:jr $ra