Chapter 3: Arithmetic for Computers

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

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

Chapter Three. Arithmetic

Divide: Paper & Pencil

Module 2: Computer Arithmetic

Floating Point Arithmetic

COMP2611: Computer Organization. Data Representation

Chapter 5 : Computer Arithmetic

Introduction to Computers and Programming. Numeric Values

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

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

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

CHW 261: Logic Design

CS101 Lecture 04: Binary Arithmetic

ECE260: Fundamentals of Computer Engineering

Organisasi Sistem Komputer

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

CO212 Lecture 10: Arithmetic & Logical Unit

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

CS 101: Computer Programming and Utilization

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

ECE 30 Introduction to Computer Engineering

Number Systems and Computer Arithmetic

CPS 104 Computer Organization and Programming

Computer Architecture Set Four. Arithmetic

COMP 303 Computer Architecture Lecture 6

Lecture 8: Addition, Multiplication & Division

ECE232: Hardware Organization and Design

Number System. Introduction. Decimal Numbers

Chapter 10 Binary Arithmetics

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

Computer Organisation CS303

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

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

Chapter 3 Arithmetic for Computers (Part 2)

Chapter 4. Operations on Data

Signed Binary Numbers

Floating Point Numbers. Lecture 9 CAP

COMP Overview of Tutorial #2

FLOATING POINT NUMBERS

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

COMPUTER ARITHMETIC (Part 1)

Number Systems. Both numbers are positive

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

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

MIPS Integer ALU Requirements

ECE331: Hardware Organization and Design

Numeric Encodings Prof. James L. Frankel Harvard University

Chapter 3 Arithmetic for Computers

Chapter 2 Bits, Data Types, and Operations

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Computer Arithmetic Ch 8

4/8/17. Admin. Assignment 5 BINARY. David Kauchak CS 52 Spring 2017

Chapter 10 - Computer Arithmetic

Computer Arithmetic Ch 8

Chapter 2 Data Representations

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

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

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

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

CHAPTER 5: Representing Numerical Data

Chapter 2 Bits, Data Types, and Operations

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

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

Inf2C - Computer Systems Lecture 2 Data Representation

Signed umbers. Sign/Magnitude otation

Chapter 3. Arithmetic Text: P&H rev

Data Representations & Arithmetic Operations

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

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

CPE300: Digital System Architecture and Design

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

Computer Arithmetic Floating Point

CS 64 Week 1 Lecture 1. Kyle Dewey

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

Data Representation 1

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


Arithmetic for Computers

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

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

unused unused unused unused unused unused

Chapter 2 Bits, Data Types, and Operations

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

Chapter 2 Bits, Data Types, and Operations

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

Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

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

More Programming Constructs -- Introduction

Data Representation in Computer Memory

3.5 Floating Point: Overview

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

Integers and Floating Point

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

IEEE Standard for Floating-Point Arithmetic: 754

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

Transcription:

Chapter 3: Arithmetic for Computers

Objectives Signed and Unsigned Numbers Addition and Subtraction Multiplication and Division Floating Point Computer Architecture CS 35101-002 2

The Binary Numbering System A computer s internal storage techniques are different from the way humans represent information in daily lives Humans Decimal numbering system to rep real numbers Base-10 Each position is a power of 10 3052 = 3 x 10 3 + 0 x 10 2 + 5 x 10 1 + 2 x 10 0 Computer Architecture CS 35101-002 3

Binary Representation of Numbers Information inside a digital computer is stored as a collection of binary data Binary numbering system Base-2 Built from ones and zeros Each position is a power of 2 1101 = 1 x 2 3 + 1 x 2 2 + 0 x 2 1 + 1 x 2 0 Digits 0,1 are called bits (binary digits) Computer Architecture CS 35101-002 4

Binary Representation of Numbers 6-Digit Binary Number (111001) 111001 = 1 x 2 5 + 1 x 2 4 + 1 x 2 3 + 0 x 2 2 + 0 x 2 1 + 1 x 2 0 = 32 + 16 + 8 + 0 + 0 + 1 = 57 5-Digit Binary Number (10111) 10111 = 1 x 2 4 +0 x 2 3 + 1 x 2 2 + 1 x 2 1 + 1 x 2 0 = 16 + 0 + 4 + 2 +1 = 23 Computer Architecture CS 35101-002 5

Binary Representation of Numbers Computers use finite number of Bits for Integer Storage Size ( word ) Max Unsigned Number Allowed 16 1x2 15 + 1x2 14 + +1x2 1 +1x2 0 MIPS-32 1x2 31 +1x2 30 + +1x2 1 + 1x2 0 Otherwise Arithmetic Overflow Computer Architecture CS 35101-002 6

Number Representation MIPS word Example: 11 ten = 1 x 2 3 +0 x 2 2 + 1 x 2 1 + 1 x 2 0 = 1011 two 31 30 29 28 7654 3210 0 0 0 0 1011 Most-significant bit Least-significant bit Computer Architecture CS 35101-002 7

Signed Number Representation Sign/Magnitude Notation Signed Number Examples: -49, +3, -8 Most significant Bit Stores sign 0 +ve number 1 -ve number Remaining Bits represent Magnitude of number -49 +3 1 0 0 0 0 0 0 0 0011 0001 0011 Find the decimal value for the 32-bit sign/magnitude notation: 1 0 0 0 0 0 0 0 Computer Architecture CS 35101-002 8

Signed Number Representation Two s Complement Notation Leading 0s mean +ve Leading 1s mean -ve 1 0 0 0 0011 0001 1 x 2 31 + 0 X2 30 + 0x2 6 + 1x2 5 + 1x2 4 + 0x2 3 + 0x2 2 +0x2 1 +1x2 0 = -2,147,483,648 + 32 +16 +1 = -2,147,483,609 Compare with sign/magnitude representation for -49 Computer Architecture CS 35101-002 9

cf: Sign Magnitude/ Two s Complement Notations Up Close Sign Magnitude Two's Complement 000 = +0 000 = +0 001 = +1 001 = +1 010 = +2 010 = +2 011 = +3 011 = +3 100 = -0 100 = -4 101 = -1 101 = -3 110 = -2 110 = -2 111 = -3 111 = -1 Computer Architecture CS 35101-002 10

MIPS 32 bit signed numbers: Two s Complement Representation Value = 0 0001 = + 1 0010 = + 2... 0111 1111 1111 1111 1111 1111 1111 1110 = + 2,147,483,646 0111 1111 1111 1111 1111 1111 1111 1111 = + 2,147,483,647 1000 = 2,147,483,648 1000 0001 = 2,147,483,647 1000 0010 = 2,147,483,646... 1111 1111 1111 1111 1111 1111 1111 1101 = 3 1111 1111 1111 1111 1111 1111 1111 1110 = 2 1111 1111 1111 1111 1111 1111 1111 1111 = 1 Computer Architecture CS 35101-002 11

Two s Complement Operation To Negate a Two's complement number: First invert all bits then Add 1 to the inverted bits To Convert 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 LHS half of the word 0010 -> 0010 1010 -> 1111 1010 Computer Architecture CS 35101-002 12

Addition and Subtraction Addition (carries 1s) 0011 = + 3 0010 = + 2 0101 = + 5 Subtraction: use addition of negative numbers 0011 = + 3 1111 1111 1111 1111 1111 1111 1111 1110 = - 2 0001 = + 1 Overflow (if result too large to fit in the finite computer word of the result register) e.g., adding two n-bit numbers does not yield an n-bit number 0111 0001 1000 Computer Architecture CS 35101-002 13

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 Computer Architecture CS 35101-002 14

Multiplication Recall: X 1000 ten 1001 ten Multiplicand Multiplier Observations 1000 1000 1001000 ten Product More storage required to store the product Place copy of multiplicand in proper location if multiplier is a 1 Place 0 in proper location if multiplier is 0 Product of n-bit Multiplicand and m-multiplier is (n + m)-bit long Number of steps (move digits to LHS) is n -1; where n rep the number of digits (1,0) Let's examine 2 versions of multiplication algorithm for binary numbers Computer Architecture CS 35101-002 15

Multiplication Version 1 Start Multiplier0 = 1 1. Test Multiplier0 Multiplier0 = 0 Multiplicand 64 bits Shift left 1a. Add multiplicand to product and place the result in Product register 64-bit ALU Multiplier Shift right 32 bits 2. Shift the Multiplicand register left 1 bit Product Write Control test 3. Shift the Multiplier register right 1 bit 64 bits Datapath Control No: < 32 repetitions 32nd repetition? Yes: 32 repetitions Done Computer Architecture CS 35101-002 16

Multiplication Refined Version Start Product0 = 1 1. Test Product0 Product0 = 0 32-bit ALU Multiplicand 32 bits Add multiplicand to bits 32 thru 63 in product register and place the result in bits 32 thru 63 of product register Product 64 bits Shift right Write Control test 3. Shift the Product register right 1 bit 32nd repetition? No: < 32 repetitions Yes: 32 repetitions Done Computer Architecture CS 35101-002 17

Multiplication Negative Numbers Convert Multiplicand and Multiplier to Positive Numbers Run the Multiplication algorithm for 31 iterations (ignoring the sign bit) Negate product only if original signs for Multiplicand and Multiplier are different Computer Architecture CS 35101-002 18

Floating Point (Overview) Binary Representation Floats Provide representation for: Decimal numbers, e.g., 3.1416 Fractions, very small numbers, e.g.,.1 First Convert number to scientific notation: +MxB +E M ~ mantissa; B ~ base (2) of exponent E ~ exponent Computer Architecture CS 35101-002 19

Floats Binary Representation: Example 5.75 5 has binary value 101.75 = ½ + ¼ = 2-1 + 2-2 = 0.11 (binary value) 5.75 = 101.11 x 2 0 (scientific notation) Normalize number: 5.75 =.10111 x 2 3 (i.e., 1/2 + 1/8 + 1/16 + 1/32) Computer Architecture CS 35101-002 20

Floating Point MIPS Sign Magnitude Representation +5.75 = +.10111 x 2 +3 31 30 29 28 0 0 0 0.... 0001 22...22 1101 101. 1100 7654 3210 Most-significant bit Show that: General Sign Magnitude Representation (-1) s xfx2 E Least-significant bit Min value of numbers is 2x10-38 Max value of numbers is 2x10 38 How do you increase the precision? Computer Architecture CS 35101-002 21

MIPS Representation Overflow/Underflow/Double Precision Exponent is too large Overflow Exponent too small Underflow MIPS solution: Double Precision representation Combine two MIPS word +5.75 = +.10111 x 2 +3 31 30 29 28 20. 7654 3210 0 0 0 0001 1101 1100 31 30 29 28. 7654 3210 0 0 0 Computer Architecture CS 35101-002 22

Floating Point IEEE 754 Representation Observations so far: We can increase the precision by making leading 1 bit of the normalized number implicit Logically 24 bits (instead of 23) for the fractional part In our representation, the exponent of 2-1 Looks like a large binary number On the other hand the exponent 2 +1 looks like a smaller binary number Let s make the most negative exponent 000 and most positive 1111111 Hence introduce a transformation (Bias) Single Precision (7 bits) subtract 127 from exponent why 7 bits? Double Precision (10 bits) subtract 1023 from exponent why 10 bits? IEEE 754 Binary Representation: (-1) s x(1 + F)x2 (E- Bias) Computer Architecture CS 35101-002 23

Floating Point IEEE 754 Binary Representation Show the IEEE 754 Single Precision Binary Representation of -0.75-0.75 = -0.11 2 x2-1 Hence, normalized notation: -1.1 2 x2-1 ------(a) cf (a) with generalized form: (-1) s x(1 + F)x2 (E- Bias) Then (a) becomes: (-1) 1 x (1 +.1 000) x 2 (126 127) 31 30 29 28.... 22...22. 7654 3210 1 0 1 1 1111 0100 Computer Architecture CS 35101-002 24

Floating Point IEEE 754 Binary Representation Show the IEEE 754 Double Precision Binary Representation of -0.75-0.75 = -0.11 2 x2-1 Hence, normalized notation: -1.1 2 x2-1 ------(a) cf (a) with generalized form: (-1) s x(1 + F)x2 (E- Bias) Then (a) becomes: (-1) 1 x (1 +.1 000) x 2 (1022 1023) 31 30 29 28 27 26 25. 23. 21 20. 7654 3210 1 0 1 1 1 111 11 1 0 0 0 0 0 0 000 00 0 0 Computer Architecture CS 35101-002 25