School of Computer Science G51CSA 1 Computer Arithmetic.

Slides:



Advertisements
Similar presentations
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Advertisements

Binary Arithmetic Binary addition Binary subtraction
Floating Point Numbers
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Computer ArchitectureFall 2007 © September 5, 2007 Karem Sakallah CS 447 – Computer Architecture.
Booth’s Algorithm.
Chapter 5 Floating Point Numbers. Real Numbers l Floating point representation is used whenever the number to be represented is outside the range of integer.
Number Systems Standard positional representation of numbers:
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Binary Representation and Computer Arithmetic
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
The Binary Number System
Simple Data Type Representation and conversion of numbers
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
Computer Arithmetic.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
Fixed-Point Arithmetics: Part II
Computer Architecture
Data Representation and Computer Arithmetic
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
Data Representation in Computer Systems
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
9.4 FLOATING-POINT REPRESENTATION
Calculating Two’s Complement. The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of.
CSC 221 Computer Organization and Assembly Language
Floating Point Arithmetic
Computer Arithmetic See Stallings Chapter 9 Sep 10, 2009
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
IT1004: Data Representation and Organization Negative number representation.
Numbers in Computers.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
William Stallings Computer Organization and Architecture 7th Edition
Luddy Harrison CS433G Spring 2007
Number Representations
Data Representation Data Types Complements Fixed Point Representation
ECEG-3202 Computer Architecture and Organization
Chapter 8 Computer Arithmetic
Chapter3 Fixed Point Representation
Numbers with fractions Could be done in pure binary
Number Representations
Presentation transcript:

School of Computer Science G51CSA 1 Computer Arithmetic

School of Computer Science G51CSA 2 Number Systems Binary: Hexadecimal: Word Size: (Fixed) number of bits used to represent a number

School of Computer Science G51CSA 3 Integer Representation Representing arbitrary numbers Human: = Computer: Only binary digits No minus signs No dot (period) Fixed point Representation: radix point (binary point) assumed to be to the right of the rightmost digit.

School of Computer Science G51CSA 4 Non Negative Integer Representation If we want to represent nonnegative integers only Then If an n-bit sequence of binary digits b n-1 b n-2 …b 0 is interpreted as an unsigned integer A, its value is An 8-bit can represent the numbers from

School of Computer Science G51CSA 5 Sign-magnitude representation Sign-magnitude representation: Most significant bit (sign bit) used to indicate the sign and the rest represent the magnitude. if sign bit = 0Positive number sign bit = 1Negative number +18 = =

School of Computer Science G51CSA 6 Sign-magnitude representation Problems with sign-magnitude representation: JAddition and subtraction: Require examination of both sign and magnitude JRepresenting zero: +0 and = =

School of Computer Science G51CSA 7 Twos complement representation Characteristics of twos complement representation and arithmetic JRange: -2 n-1 to 2 n-1 - 1, one zero (For an n-bit word) JNegation: Take the Boolean complement of each bit of the corresponding positive number and add 1 to the resulting bit pattern JExpansion of bit length: Add additional bit positions to the left and fill in with the value of the original sign bit. JOverflow rule: If two numbers have the same sign are added, then overflow occurs iif (if and only if) the result has the opposite sign. JSubtraction Rule: To subtract B from A, take the twos complement of B and add it to A

School of Computer Science G51CSA 8 Conversion between twos complement and decimal DecimalSign Twos MagnitudeComplement DecimalSign Twos MagnitudeComplement Twos complement representation Awkward to human, but very convenient for computer….

School of Computer Science G51CSA 9 Conversion between twos complement and decimal Twos complement representation Value range for an n-bit number Positive Number Range: 0 ~ 2 n-2 Negative number range: -1 ~ - 2 n-2 Examples:

School of Computer Science G51CSA 10 Conversion between different bit lengths +18 = (sign magnitude, 8-bit) +18 = (sign magnitude, 16-bit) -18 = (sign magnitude, 8-bit) -18 = (sign magnitude, 16-bit) +18 = (twos complement, 8-bit) +18 = (twos complement, 16-bit) -18 = (twos complement, 8-bit) -18 = (twos complement, 16-bit) Fixed point Representation Twos complement representation

School of Computer Science G51CSA 11 Integer Arithmetic Negation Sign-magnitude: Invert the sign bit Twos complement: JInvert each bit (including the sign bit). JTreat the result as unsigned binary integer, and add 1 E.g.

School of Computer Science G51CSA 12 Integer Arithmetic Addition and Subtraction Overflow Result larger than can be held in the word size being used resulting in overflow. If two numbers have the same sign are added, then overflow occurs iif (if and only if) the result has the opposite sign. Carry bit ignored

School of Computer Science G51CSA 13 Subtraction To subtract one number (subtrahend) from another number minuend), take the twos complement (negation) of the subtrahend and add it to the minuend. Integer Arithmetic (M - S) Overflow rule applies here also

School of Computer Science G51CSA 14 Integer Arithmetic Addition and Subtraction Hardware Block Diagram

School of Computer Science G51CSA 15 Integer Arithmetic Multiplication: Unsigned binary integers

School of Computer Science G51CSA 16 Integer Arithmetic Multiplication Flowchart for unsigned binary multiplication

School of Computer Science G51CSA 17 Integer Arithmetic (IV) Division: Unsigned binary integer

School of Computer Science G51CSA 18 JNumbers with fractions JCould be done in pure binary = =9.625 JWhere is the binary point? JFixed? Very limited - cannot represent very large or very small numbers JMoving? How do you show where it is? Real Numbers

School of Computer Science G51CSA 19 Floating Point Representation Principles Scientific notation: Slide the decimal point to a convenient location Keep track of the decimal point use the exponent of 10 Do the same with binary number in the form of JSign: + or - JSignificant: S JExponent: E

School of Computer Science G51CSA 20 Floating Point Representation Example J32-bit floating point format. JLeftmost bit = sign bit (0 positive or 1 negative). JExponent in the next 8 bits. Use a biased representation. A fixed value, called bias, is subtracted from the field to get the true exponent value. Typically, bias = 2 k-1 - 1, where k is the number of bits in the exponent field. Also known as excess-N format, where N = bias = 2 k (The bias could take other values) In this case: 8-bit exponent field, Bias = 127. Exponent range -127 to +128 JFinal portion of word (23 bits in this example) is the significant (sometimes called mantissa).

School of Computer Science G51CSA 21 Floating Point Representation Many ways to represent a floating point number, e.g., Normalization: Adjust the exponent such that the leading bit (MSB) of mantissa is always 1. In this example, a normalized nonzero number is in the form JLeft most bit always 1 - no need to store J23-bit field used to store 24-bit mantissa with a value between 1 to 2

School of Computer Science G51CSA 22 Floating Point Representation JSign stored in the first bit JLeft most bit of the TRUE mantissa always 1 - no need to store JThe value of 127 is added to the TRUE exponent to be stored JThe base is 2

School of Computer Science G51CSA 23 Floating Point Representation JExpressible Numbers

School of Computer Science G51CSA 24 Floating Point Representation The number of individual values - same for any fixed length binary Range: Precision: 1816 JRange and Precision

School of Computer Science G51CSA 25 IEEE 754 Standard Floating Point Representation (VII) JSingle Format and Double Format 1Single Precision format: 132 bits, sign = 1 bit, Exponent = 8bits, Mantissa = 32 bits 1Numbers are normalised to form: ; where b = 0 or 1 1Exponent formatted using excess-127 notation with implied base of 2 1Theoretical exponent range to Actuality, exponent values of 0 and 255 used for special values 1Exponent range restricted to -126 to defined by a mantissa of 0 and the special exponent value of 0 1Allows + - infinity defined by a mantissa value of 0 and exponent value 255

School of Computer Science G51CSA 26 Floating Point Arithmetic Addition and Subtraction JCheck for zero JAlign the significants JAdd or subtract the significants JNormalise the result E.g x x x x 10 -1