Divide: Paper & Pencil

Similar documents
Number Systems and Computer Arithmetic

Module 2: Computer Arithmetic

Floating Point Arithmetic

361 div.1. Computer Architecture EECS 361 Lecture 7: ALU Design : Division

COMP 303 Computer Architecture Lecture 6

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

MIPS Integer ALU Requirements

Divide: Paper & Pencil CS152. Computer Architecture and Engineering Lecture 7. Divide, Floating Point, Pentium Bug. DIVIDE HARDWARE Version 1

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

Organisasi Sistem Komputer

EE260: Logic Design, Spring n Integer multiplication. n Booth s algorithm. n Integer division. n Restoring, non-restoring

Review: MULTIPLY HARDWARE Version 1. ECE4680 Computer Organization & Architecture. Divide, Floating Point, Pentium Bug

Chapter 3: Arithmetic for Computers

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

Number Representations

Introduction to Computers and Programming. Numeric Values

CO212 Lecture 10: Arithmetic & Logical Unit

Chapter 5 : Computer Arithmetic

Chapter 4 Section 2 Operations on Decimals

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

Floating-point representations

Floating-point representations

Chapter Three. Arithmetic

COMPUTER ORGANIZATION AND DESIGN

UNIT-III COMPUTER ARTHIMETIC

EECS150 - Digital Design Lecture 13 - Combinational Logic & Arithmetic Circuits Part 3

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

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS Arithmetic (a) The four possible cases Carry (b) Truth table x y

Chapter 4. Operations on Data

Floating Point Numbers

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Computer Architecture and Engineering Lecture 7: Divide, Floating Point, Pentium Bug

CPS 104 Computer Organization and Programming

ECE331: Hardware Organization and Design

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Number Systems. Both numbers are positive

Chapter 3 Arithmetic for Computers (Part 2)

Homework 3. Assigned on 02/15 Due time: midnight on 02/21 (1 WEEK only!) B.2 B.11 B.14 (hint: use multiplexors) CSCI 402: Computer Architectures

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

Computer Arithmetic Floating Point

CPE300: Digital System Architecture and Design

Computer Arithmetic Ch 8

Computer Arithmetic Ch 8

Integer Multiplication. Back to Arithmetic. Integer Multiplication. Example (Fig 4.25)

COMPUTER ARITHMETIC (Part 1)

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

Chapter 2 Data Representations

Chapter 3. Arithmetic Text: P&H rev

Lecture 8: Addition, Multiplication & Division

Data Representations & Arithmetic Operations

CHW 261: Logic Design

Number Systems CHAPTER Positional Number Systems

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

ECE232: Hardware Organization and Design

CSE 141 Computer Architecture Summer Session Lecture 3 ALU Part 2 Single Cycle CPU Part 1. Pramod V. Argade

Thomas Polzer Institut für Technische Informatik

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

CO Computer Architecture and Programming Languages CAPL. Lecture 15

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

CHAPTER 5: Representing Numerical Data

Exponential Numbers ID1050 Quantitative & Qualitative Reasoning

3.5 Floating Point: Overview

Arithmetic Logic Unit

COMPUTER ORGANIZATION AND. Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

EEC 483 Computer Organization

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

ECE260: Fundamentals of Computer Engineering

COMPUTER ORGANIZATION AND ARCHITECTURE

Computer Architecture and IC Design Lab. Chapter 3 Part 2 Arithmetic for Computers Floating Point

Foundations of Computer Systems

Internal Data Representation

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

Arithmetic for Computers. Hwansoo Han

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

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

FLOATING POINT NUMBERS

At the ith stage: Input: ci is the carry-in Output: si is the sum ci+1 carry-out to (i+1)st state

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

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

Chapter 3 Arithmetic for Computers

Computer Organisation CS303

Scientific Computing. Error Analysis

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

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

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

CS 101: Computer Programming and Utilization

Signed umbers. Sign/Magnitude otation

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

COMP2611: Computer Organization. Data Representation

Computer Architecture and Organization

CS321. Introduction to Numerical Methods

Integer Multiplication and Division

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

Floating Point Numbers. Lecture 9 CAP

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers Implementation

Floating-Point Arithmetic

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

Characters, Strings, and Floats

Floating Point Representation in Computers

Chapter 10 - Computer Arithmetic

Transcription:

Divide: Paper & Pencil 1001 Quotient Divisor 1000 1001010 Dividend -1000 10 101 1010 1000 10 Remainder See how big a number can be subtracted, creating quotient bit on each step Binary => 1 * divisor or 0 * divisor Dividend = Quotient x Divisor + Remainder DIVIDE HARDWARE Version 1 64-bit Divisor reg, 64-bit ALU, 64-bit Remainder reg, 32-bit Quotient reg

Divide Algorithm Version 1 Takes n+1 steps for n-bit Quotient & Rem. Quotient Divisor Remainder 0000 0011 0000 0000 0111 Start 1. Subtract the Divisor register from the Remainder register, and place the result in the Remainder register. Remainder >= 0 Test Remainder Remainder < 0 2a. Shift the Quotient register to the left setting the new rightmost bit to 1. 2b. Restore the original value by adding the Divisor register to the Remainder register, and place the sum in the Remainder register. Also shift the Quotient register to the left, setting the new least significant bit to 0. 3. Shift the Divisor register right 1 bit. 33rd repetition? No: < 33 repetitions Done Yes: 33 repetitions DIVIDE HARDWARE Version 3 32-bit Divisor reg, 32 -bit ALU, 64-bit Remainder reg, (0-bit Quotient reg)

Observations on Divide Version 3 Same Hardware as Multiply: just need ALU to add or subtract, and 63-bit register to shift left or shift right Hi and Lo registers in MIPS combine to act as 64-bit register for multiply and divide Signed Divides: Simplest is to remember signs, make positive, and complement quotient and remainder if necessary Note: Dividend and Remainder must have same sign Note: Quotient negated if Divisor sign & Dividend sign disagree So Far Can do logical, add, subtract, multiply, divide,... But... what about fractions? what about really large numbers?

Binary Fractions 1011 2 = 1x2 3 + 0x2 2 + 1x2 1 + 1x2 0 so... 101.011 2 = 1x2 2 + 0x2 1 + 1x2 0 + 0x2-1 + 1x2-2 + 1x2-3 e.g.,.75 = 3/4 = 3/2 2 = 1/2 + 1/4 =.11 Recall Scientific Notation decimal point exponent sign 23-24 +6.02 x 10 1.673 x 10 Mantissa radix (base) Issues: Arithmetic (+, -, *, / ) Representation, Normal form Range and Precision Rounding Exceptions (e.g., divide by zero, overflow, underflow) Errors Properties ( negation, inversion, if A = B then A - B = 0 )

Floating-Point Numbers Representation of floating point numbers in IEEE 754 standard: 1 8 23 single precision N = (-1) S 2 E-127 (1.M) sign S E M exponent: excess 127 binary integer (actual exponent is e = E - 127) 0 < E < 255 0 = 0 00000000 0... 0-1.5 = 1 01111111 10... 0 325 = 101000101 X 2 0 = 1.01000101 X 2 8 = 0 10000111 01000101000000000000000.02 =.0011001101100... X 2 0 = 1.1001101100... X 2-3 = 0 01111100 1001101100... range of about 2 X 10-38 to 2 X 10 38 always normalized (so always leading 1, thus never shown) special representation of 0 (E = 00000000) (why?) can do integer compare for greater-than, sign mantissa: sign + magnitude, normalized binary significandw/ hidden integer bit: 1.M Double Precision Floating Point Representation of floating point numbers in IEEE 754 standard: 1 11 20 double precision sign actual exponent is e = E - 1023 N = (-1) S 2 E-1023(1.M) S E M exponent: excess 1023 binary integer 0 < E < 2048 52 (+1) bit mantissa range of about 2 X 10-308 to 2 X 10 308 mantissa: sign + magnitude, normalized binary significandw/ hidden integer bit: 1.M 32 M

Floating Point Addition How do you add in scientific notation? 9.962 x 10 4 + 5.231 x 10 2 Basic Algorithm 1. Align 2. Add 3. Normalize 4. Round FP Addition Hardware

Floating Point Multiplication How do you multiply in scientific notation? (9.9 x 10 4 )(5.2 x 10 2 ) = 5.148 x 10 7 Basic Algorithm 1. Add exponents 2. Multiply 3. Normalize 4. Round 5. Set Sign FP Accuracy Extremely important in scientific calculations Very tiny errors can accumulate over time IEEE 754 FP standard has four rounding modes always round up (toward + ) always round down (toward - ) truncate round to nearest => in case of tie, round to nearest even Requires extra bits in intermediate representations

Extra Bits for FP Accuracy Guard bits -- bits to the right of the least significant bit of the significand computed for use in normalization (could become significant at that point) and rounding. IEEE 754 has three extra bits and calls them guard, round, and sticky. Key Points Multiplication and division take much longer than addition, requiring multiple addition steps. Floating Point extends the range of numbers that can be represented, at the expense of precision (accuracy). FP operations are very similar to integer, but with pre- and post-processing. Rounding implementation is critical to accuracy over time.