Chapter Three. Arithmetic

Similar documents
Computer Architecture Set Four. Arithmetic

Floating Point Arithmetic

Chapter 3 Arithmetic for Computers

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

Chapter 3: Arithmetic for Computers

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Divide: Paper & Pencil

COMP2611: Computer Organization. Data Representation

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

Number Systems and Their Representations

3.5 Floating Point: Overview

Numeric Encodings Prof. James L. Frankel Harvard University

Arithmetic for Computers

Floating Point Numbers. Lecture 9 CAP

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

ECE260: Fundamentals of Computer Engineering

CS101 Lecture 04: Binary Arithmetic

Scientific Computing. Error Analysis

Introduction to Computers and Programming. Numeric Values

MIPS Integer ALU Requirements

CO212 Lecture 10: Arithmetic & Logical Unit

We are quite familiar with adding two numbers in decimal

Module 2: Computer Arithmetic

IEEE Standard for Floating-Point Arithmetic: 754

ECE232: Hardware Organization and Design

ecture 25 Floating Point Friedland and Weaver Computer Science 61C Spring 2017 March 17th, 2017

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

CENG 3420 Lecture 05: Arithmetic and Logic Unit

CSCI 402: Computer Architectures. Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI.

CPE 335 Computer Organization. MIPS Arithmetic Part I. Content from Chapter 3 and Appendix B

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

Review: MIPS Organization

CS 101: Computer Programming and Utilization

CS 61C: Great Ideas in Computer Architecture Floating Point Arithmetic

Inf2C - Computer Systems Lecture 2 Data Representation

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

CENG3420 L05: Arithmetic and Logic Unit

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Chapter 3 Arithmetic for Computers

CS61C L10 MIPS Instruction Representation II, Floating Point I (6)

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Number Systems. Both numbers are positive

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

Computer Arithmetic Floating Point

Floating-point representations

Floating-point representations

CHAPTER 5: Representing Numerical Data

Computer Architecture. Chapter 3: Arithmetic for Computers

CS61C : Machine Structures

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

15213 Recitation 2: Floating Point

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Arithmetic for Computers. Hwansoo Han

Number Systems and Computer Arithmetic

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Outline. What is Performance? Restating Performance Equation Time = Seconds. CPU Performance Factors

CS 61C: Great Ideas in Computer Architecture Performance and Floating-Point Arithmetic

MACHINE LEVEL REPRESENTATION OF DATA

Five classic components

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

COMPUTER ORGANIZATION AND DESIGN

Floating Point Representation. CS Summer 2008 Jonathan Kaldor

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

CS61C : Machine Structures

Signed umbers. Sign/Magnitude otation

CS 61C: Great Ideas in Computer Architecture Performance and Floating Point Arithmetic


Organisasi Sistem Komputer

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

Number Representations

Floating-Point Arithmetic

EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

CO Computer Architecture and Programming Languages CAPL. Lecture 13 & 14

Arithmetic. Chapter 3 Computer Organization and Design

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Numerical Representations On The Computer: Negative And Rational Numbers

Chapter 3 Arithmetic for Computers. ELEC 5200/ From P-H slides

Computer Organisation CS303

IEEE-754 floating-point

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Number Representations

Floating-Point Arithmetic

Thomas Polzer Institut für Technische Informatik

CS61C : Machine Structures

Numerical Representations On The Computer: Negative And Rational Numbers

CS61C : Machine Structures

CHW 261: Logic Design

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Data Representation Floating Point

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

5DV118 Computer Organization and Architecture Umeå University Department of Computing Science Stephen J. Hegner. Topic 3: Arithmetic

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 5 2/22/2018

Transcription:

Chapter Three 1 Arithmetic Where we've been: Performance (seconds, cycles, instructions) Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: Implementing the Architecture operation a b 32 32 ALU 32 result 2

Numbers Bits are just bits (no inherent meaning) conventions define relationship between bits and numbers Binary numbers (base 2) 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001... decimal: 0...2 n -1 Of course it gets more complicated: numbers are finite (overflow) fractions and real numbers negative numbers e.g., no MIPS subi instruction; addi can add a negative number) How do we represent negative numbers? i.e., which bit patterns will represent which numbers? 3 Possible Representations Sign Magnitude: One's Complement Two's Complement 000 = +0 000 = +0 000 = +0 001 = +1 001 = +1 001 = +1 010 = +2 010 = +2 010 = +2 011 = +3 011 = +3 011 = +3 100 = -0 100 = -3 100 = -4 101 = -1 101 = -2 101 = -3 110 = -2 110 = -1 110 = -2 111 = -3 111 = -0 111 = -1 Issues: balance, number of zeros, ease of operations Which one is best? Why? 4

MIPS 32 bit signed numbers: 0000 0000 0000 0000 0000 0000 0000 0000 two = 0 ten 0000 0000 0000 0000 0000 0000 0000 0001 two = + 1 ten 0000 0000 0000 0000 0000 0000 0000 0010 two = + 2 ten... 0111 1111 1111 1111 1111 1111 1111 1110 two = + 2,147,483,646 ten 0111 1111 1111 1111 1111 1111 1111 1111 two = + 2,147,483,647 ten 1000 0000 0000 0000 0000 0000 0000 0000 two = 2,147,483,648 ten 1000 0000 0000 0000 0000 0000 0000 0001 two = 2,147,483,647 ten 1000 0000 0000 0000 0000 0000 0000 0010 two = 2,147,483,646 ten... 1111 1111 1111 1111 1111 1111 1111 1101 two = 3 ten 1111 1111 1111 1111 1111 1111 1111 1110 two = 2 ten 1111 1111 1111 1111 1111 1111 1111 1111 two = 1 ten maxint minint 5 Two's Complement Operations Negating a two's complement number: invert all bits and add 1 remember: negate and invert are quite different! Converting n bit numbers into numbers with more than n bits: MIPS 16 bit immediate gets converted to 32 bits for arithmetic copy the most significant bit (the sign bit) into the other bits 0010 -> 0000 0010 1010 -> 1111 1010 "sign extension" (lbu vs. lb) 6

Addition & Subtraction Just like in grade school (carry/borrow 1s) 0111 0111 0110 + 0110-0110 - 0101 Two's complement operations easy subtraction using addition of negative numbers 0111 + 1010 Overflow (result too large for finite computer word): e.g., adding two n-bit numbers does not yield an n-bit number 0111 + 0001 note that overflow term is somewhat misleading, 1000 it does not mean a carry overflowed 7 Detecting Overflow No overflow when adding a positive and a negative number No overflow when signs are the same for subtraction Overflow occurs when the value affects the sign: overflow when adding two positives yields a negative or, adding two negatives gives a positive or, subtract a negative from a positive and get a negative or, subtract a positive from a negative and get a positive Consider the operations A + B, and A B Can overflow occur if B is 0? Can overflow occur if A is 0? 8

Effects of Overflow An exception (interrupt) occurs Control jumps to predefined address for exception Interrupted address is saved for possible resumption Details based on software system / language example: flight control vs. homework assignment Don't always want to detect overflow new MIPS instructions: addu, addiu, subu note: addiu still sign-extends! note: sltu, sltiu for unsigned comparisons 9 Floating-Point What can be represented in N bits? Unsigned 0 to 2 N 2s Complement -2 N-1 to 2 N-1-1 But, what about? very large numbers? 9,349,398,989,787,762,244,859,087,678 very small number? 0.0000000000000000000000045691 rationals 2/3 irrationals transcendentals 2 e, π 10

Floating Point We need a way to represent numbers with fractions, e.g., 3.1416 very small numbers, e.g.,.000000001 very large numbers, e.g., 3.15576 10 9 Representation: sign, exponent, significand: ( 1) sign significand 2 exponent more bits for significand gives more accuracy more bits for exponent increases range IEEE 754 floating point standard: single precision: 8 bit exponent, 23 bit significand double precision: 11 bit exponent, 52 bit significand 11 Recall Scientific Notation decimal point exponent Sign, magnitude 23-24 6.02 x 10 1.673 x 10 Mantissa Sign, magnitude radix (base) IEEE F.P. ± 1.M x 2 e - 127 Issues: Arithmetic (+, -, *, / ) Representation, Normal form Range and Precision Rounding Exceptions (e.g., divide by zero, overflow, underflow) Errors 12

IEEE 754 floating-point standard Leading 1 bit of significand is implicit Exponent is biased to make sorting easier all 0s is smallest exponent all 1s is largest bias of 127 for single precision and 1023 for double precision summary: ( 1) sign (1+significand) 2exponent bias Example: decimal: -.75 = -3/4 = -3/2 2 binary: -.11 = -1.1 x 2-1 floating point: exponent = 126 = 01111110 IEEE single precision: 10111111010000000000000000000000 13 IEEE 754 Standard Representation of floating point numbers in IEEE 754 standard: 1 8 23 single precision sign S E M actual exponent is e = E - 127 exponent: bias 127 binary integer 0 < E < 255 S E-127 N = (-1) 2 (1.M) 0 = 0 00000000 0... 0-1.5 = 1 01111111 10... 0 mantissa: sign + magnitude, normalized binary significand w/ hidden integer bit: 1.M Magnitude of numbers that can be represented is in the range: 2-126 (1.0) to 2 127 (2-2 -23 ) which is approximately: 1.8 x 10-38 to 3.40 x 10 38 14