CO212 Lecture 10: Arithmetic & Logical Unit

Similar documents
COMPUTER ARITHMETIC (Part 1)

Module 2: Computer Arithmetic

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

Divide: Paper & Pencil

COMP2611: Computer Organization. Data Representation

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

Chapter 10 - Computer Arithmetic

Numeric Encodings Prof. James L. Frankel Harvard University

Floating Point Arithmetic

Organisasi Sistem Komputer

Floating-point representations

Floating-point representations

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

Chapter 5 : Computer Arithmetic

ECE232: Hardware Organization and Design

Chapter 3: Arithmetic for Computers

The Sign consists of a single bit. If this bit is '1', then the number is negative. If this bit is '0', then the number is positive.

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

C NUMERIC FORMATS. Overview. IEEE Single-Precision Floating-point Data Format. Figure C-0. Table C-0. Listing C-0.

CS 101: Computer Programming and Utilization

Floating Point Numbers

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

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

Chapter Three. Arithmetic

Number Systems and Computer Arithmetic

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

Lecture 5. Computer Arithmetic. Ch 9 [Stal10] Integer arithmetic Floating-point arithmetic

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Inf2C - Computer Systems Lecture 2 Data Representation

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

MIPS Integer ALU Requirements

Floating Point Numbers. Lecture 9 CAP

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

FLOATING POINT NUMBERS

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Number Systems CHAPTER Positional Number Systems

3.5 Floating Point: Overview

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

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Chapter 2 Data Representations

CPE300: Digital System Architecture and Design

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

Representing and Manipulating Floating Points

Computer Arithmetic Ch 8

Computer Arithmetic Ch 8

Foundations of Computer Systems

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

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

Chapter 2. Data Representation in Computer Systems

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

Data Representations & Arithmetic Operations

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

CHAPTER 5: Representing Numerical Data

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Chapter 4 Section 2 Operations on Decimals

Representing and Manipulating Floating Points

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

CHW 261: Logic Design

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

15213 Recitation 2: Floating Point

Binary Addition & Subtraction. Unsigned and Sign & Magnitude numbers

Number System. Introduction. Decimal Numbers

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

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

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

Floating Point Numbers

MACHINE LEVEL REPRESENTATION OF DATA

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

COMPUTER ORGANIZATION AND ARCHITECTURE

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Internal Data Representation

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

Floating Point January 24, 2008

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

carry in carry 1101 carry carry

Floating Point. CSE 238/2038/2138: Systems Programming. Instructor: Fatma CORUT ERGİN. Slides adapted from Bryant & O Hallaron s slides

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

Chapter 3: part 3 Binary Subtraction

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

Representing and Manipulating Floating Points

Representing and Manipulating Floating Points. Jo, Heeseung

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Chapter 4. Operations on Data

Floating point. Today. IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.

COMP Overview of Tutorial #2

CS 33. Data Representation (Part 3) CS33 Intro to Computer Systems VIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

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

Giving credit where credit is due

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

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

Giving credit where credit is due

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

System Programming CISC 360. Floating Point September 16, 2008

Floating Point : Introduction to Computer Systems 4 th Lecture, May 25, Instructor: Brian Railing. Carnegie Mellon

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

Transcription:

CO212 Lecture 10: Arithmetic & Logical Unit Shobhanjana Kalita, Dept. of CSE, Tezpur University Slides courtesy: Computer Architecture and Organization, 9 th Ed, W. Stallings

Integer Representation For purposes of computer storage and processing, however, we do not have the benefit of special symbols for the minus sign and radix point. Only binary digits (0 and 1) may be used to represent numbers. If we are limited to nonnegative integers 8-bit word can represent the numbers from 0 to 255 If we are to include negative numbers as well, there are different conventions such as Sign-Magnitude representation 1 s complement representation 2 s complement representation

Integer Representation Sign and Magnitude The simplest form of representation employs the MSB as a sign bit If the sign bit is 0, the number is positive; if the sign bit is 1, the number is negative. In an n-bit word, the rightmost (n 1) bits hold the magnitude of the integer. Example: Disadvantages: Addition and subtraction become complex Two representations of 0

Integer Representation 1 s complement 1 s complement representation also uses the MSB as a sign bit making it easy to test whether an integer is positive or negative Negative of a number is obtained by inverting all of the bits of the positive binary value Range of values: (2^(n 1) 1) to +(2^(n 1) 1) Example: +18 = 00010010 18 = 11101101 Addition and subtraction is simple addition of two binary numbers Disadvantage: Two representation for zero: 00000000 is +0 and 11111111 is 0

Integer Representation 2 s complement 2 s complement representation also uses the MSB as a sign bit making it easy to test whether an integer is positive or negative Negative of a number is obtained by inverting all of the bits of the positive binary value and adding a 1 to the result Range of values: (2^(n 1)) to +(2^(n 1) 1) Example: +18 = 00010010 18 = 11101110 Addition and subtraction is simple addition of two binary numbers One representation for zero: 00000000 is 0

Integer Representation Most computer integer representations of computer uses 2 s complement Other signed integer representations may be used - Biased representation: add a bias value to the number and represent using the corresponding binary equivalent Fixed Point Representation Aforementioned representation are called fixed point representations because the radix point is assumed to have fixed position right of the rightmost digit (LSB)

Integer Arithmetic 2 s complement Negation Take the Boolean complement of each bit of the integer, add 1 to the result Negative of negative is positive Negative of -128??

Integer Arithmetic 2 s complement Addition and Subtraction Addition proceeds as simple addition of two unsigned integers In some instances, if there is a carry bit beyond the end of the word it is ignored. If the result is larger than can be held in the word size being used it is called overflow. When overflow occurs, the ALU must signal so that the result is not used for processing OVERFLOW RULE: If two numbers are added, and they are both positive or both negative, then overflow occurs if and only if the result has the opposite sign. Subtraction is achieved using addition. SUBTRACTION RULE: To subtract one number (subtrahend) from another (minuend), take the twos complement (negation) of the subtrahend and add it to the minuend.

Integer Arithmetic 2 s complement Multiplication Multiplication of positive numbers is straightforward 4-bit multiplied to 4-bit results in 8-bits For negative numbers, simple multiplication of 2 s complement value will not give the correct result (Eg. -5 * -3 = -113) Filling up the left most values in the partial product with binary 1s.

Integer Arithmetic 2 s complement Division Division of unsigned binary integers is straightforward 2 s complement division for negative numbers can be done by converting the operands into unsigned values perform division and then account for the sign on the resultant quotient D = Q * V + R sign(r) = sign(d) sign(q) = sign(d) * sign(v)

Floating Point Representation By assuming a fixed binary or radix point, numbers with a fractional component may be represented - but limited in the range of numbers Solution: Use scientific notation (floating point) 976,000,000,000,000 = 9.76 * 10^14, and 0.0000000000000976 = 9.76 * 10^(-14) Any number can be represented in the form Sign: + or ; Significand S; Exponent E The base B is implicit and is the same for all numbers

Floating Point Representation Sign 0 for positive; 1 for negative numbers Exponent Exponent is stored using a biased representation A fixed value, called the bias, is subtracted from the field to get the true exponent value Typically, bias is (2^(k 1) 1), where k is the number of bits in the binary exponent For an 8-bit field the range of unsigned numbers is 0 to 255 Bias = 2^7 1 = 127, actual exponent values are in the range -127 to +128 Advantage of biased representation: Comparison is easier

Floating Point Representation Significand A floating point number can have many representations To simplify operations need a standard representation normalization For a base 2 representation a normal number is one in which the MSB is of the significand is 1 i.e. In such normal numbers MSB is implicit, not stored 23bit field is used to store 24 bit significand The representation as presented will not accommodate a value of 0 include a special bit-pattern of 0

Floating Point Representation Overflow when an arithmetic operation results in an absolute value greater than can be expressed with an exponent of 128 Underflow when the fractional magnitude is too small less serious problem because result can generally be approximated by 0

Floating Point Representation Trade offs Numbers represented in floating-point notation are not spaced evenly along the number line, unlike fixed-point numbers Range determines maximum and minimum number of values that can be represented Precision determines the minimum value fractional value that can be represented accurately Trade-off between range and precision: more number of bits in significand => more precision more number of bits in exponent => greater range

Floating Point IEEE standard IEEE standard 754 for floating point numbers was developed to facilitate portability of programs from one processor to another 3 basic binary formats defined with lengths of 32, 64, and 128 bits Exponents of length 8, 11, 15 respectively The standard defines extended precision formats, which extend a supported basic format by providing additional bits in the exponent (extended range) and in the significand (extended precision) Defines only standards; implementation dependent

Floating Point IEEE standard

Floating Point Arithmetic For addition and subtraction both operands must have the same exponent value This may require shifting the radix point on one of the operands to achieve alignment Multiplication and division are more straightforward.

Floating Point Arithmetic A floating-point operation may produce one of these conditions: Exponent overflow: A positive exponent exceeds the maximum possible exponent value; may be designated as + or. Exponent underflow: A negative exponent is less than the minimum possible exponent value; it may be reported as 0. Significand underflow: While aligning significands, digits may flow off the right end of the significand; requires rounding Significand overflow: Addition of two significands of the same sign may result in a carry out of the most significant bit; requires realignment

Floating Point Arithmetic In floating-point arithmetic, addition and subtraction are more complex than multiplication and division need for alignment. There are four basic phases of the algorithm for addition and subtraction 1. Check for zeros 2. Align the significands 3. Add or subtract the significands 4. Normalize the result.

Floating Point Guard Bits For a floating-point operation, the exponent and significand of each operand are loaded into ALU registers In case of significand, the length of the register is greater than the length of the significand plus an implied bit The register contains additional bits, called guard bits, which are used to pad out the right end of the significand with 0s Important: to maintain precision Example: x = 1.00...00 * 2^1 and y = 1.11...11 * 2^0

Floating Point Rounding The result of any operation on the significands is generally stored in a longer register When the result is put back into the floating-point format, the extra bits must be eliminated in such a way as to produce a result that is close to the exact result rounding. Round to nearest: The result is rounded to the nearest representable number Round toward + : The result is rounded up toward plus infinity. Round toward : The result is rounded down toward negative infinity Round toward 0: The result is rounded toward zero.

Floating Point Special cases: Denormalized numbers When exponent is all 0 s, it is considered a special case and the floating point number thus represented is assumed to be a denormalized number i.e. the implicit integral part of the significand is assumed to be 0 (not 1) To represent 0: Exponent all 0 s, significand all 0 s To signal error conditions: overflow, underflow, division by 0 NaN (not a number) Exponent of all 0 s and non=zero significand