1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.

Slides:



Advertisements
Similar presentations
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Advertisements

Computer ArchitectureFall 2007 © September 5, 2007 Karem Sakallah CS 447 – Computer Architecture.
Booth’s Algorithm.
Assembly Language and Computer Architecture Using C++ and Java
Number Systems Standard positional representation of numbers:

Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Number Systems Lecture 02.
Binary Number Systems.
School of Computer Science G51CSA 1 Computer Arithmetic.
Binary Representation and Computer Arithmetic
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
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 Architecture
Data Representation and Computer Arithmetic
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
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
Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy.
Number Systems and Codes. CS2100 Number Systems and Codes 2 NUMBER SYSTEMS & CODES Information Representations Number Systems Base Conversion Negative.
CSC 221 Computer Organization and Assembly Language
ECE 456 Computer Architecture
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Floating Point Representations
CS2100 Computer Organisation
Programming and Data Structure
Dr. Clincy Professor of CS
Number Representation
Dr. Clincy Professor of CS
William Stallings Computer Organization and Architecture 7th Edition
CS1010 Programming Methodology
Data Structures Mohammed Thajeel To the second year students
Luddy Harrison CS433G Spring 2007
Chapter 2 Bits, Data Types & Operations Integer Representation
Number Representations
Data Representation Data Types Complements Fixed Point Representation
ECEG-3202 Computer Architecture and Organization
Computer Architecture
Chapter 8 Computer Arithmetic
Chapter3 Fixed Point Representation
Numbers with fractions Could be done in pure binary
Number Representations
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1

CE 454Ahmed Ezzat 2 Outline Number Systems Data Representation Integer Data Representation Integer Arithmetic Operations Real Numbers Floating Point Representation Floating Point Arithmetic Operations

CE 454Ahmed Ezzat 3 Number Systems Binary Octal Hexadecimal Word Size: (Fixed) number of bits used to represent a number

CE 454Ahmed Ezzat 4 Number Systems: Binary Numbers Binary: Base 2 number system – 0 and 1 – Positional system 101 decimal = – A binary number 111 means 1 x x x 2 2 = 7 (decimal)

CE 454Ahmed Ezzat 5 Number Systems: Octal and Hexadecimal Octal: Base 8 number system – 0-7 – 345 o means 5 x x x 8 2 = (decimal) Hexadecimal: Base 16 number system – 0-9, A, B, C, D, E, F A 16 = 10 10, B 16 = 11 10, … F 16 = 15 – 0xABC is equal to x x x 16 2 = 2748 Bytes (8 bits) are sometimes written in oct/hex for convenience

CE 454Ahmed Ezzat 6 Data Representation Computers represent information as 0s and 1s – This includes: Programs Input/Output Information Intermediate Variables Characters are encoded using the ASCII table providing 7-bits per character. Default of an ASCII character is 8-bits (8 th bit used for parity) – The character ‘A’ is encoded as an integer in binary is character ‘A’ in ASCII More complex examples of binary representations: – Extended 8 bits – Unicode 16 bits (Internationalization) Binary, Octal, or Hexadecimal for integers Floating Point for real numbers Etc.

CE 454Ahmed Ezzat 7 Integer Data Representation Representing arbitrary numbers Human: = Computer:  Only binary digits  No minus sign  No dot (period) Fixed Point Representation: radix point (binary point) assumed to be to the right of the rightmost digit

CE 454Ahmed Ezzat 8 An 8-bit can represent the numbers from Integer Data Representation: Non Negative Integers 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, and its value is:

CE 454Ahmed Ezzat 9                   0 if n-1 n i i i n i i i bbA bbA A +18 = = Integer Data Representation: 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 = 0 Positive number sign bit = 1 Negative number

CE 454Ahmed Ezzat 10 Integer Data Representation: Sign- Magnitude Representation Problems with sign-magnitude representation:  Addition and subtraction  Require examination of both sign and magnitude  Representing zero: +0 and –0  +0 =  -0 =

CE 454Ahmed Ezzat 11 Integer Data Representation: 2’s Complement Representation Characteristics of 2’s complement representation and arithmetic : 2’s complement turns subtraction into addition Range: -2 n-1 to (2 n-1 – 1), one zero (For an n-bit word) Negative: Take the Boolean complement (1’s complement) of each bit of the corresponding positive number and add 1 to the resulting pattern Expansion of bit length: Add additional bit position to the left and fill in with the value of the original sign bit Overflow rule: If two numbers have the same sign are added, then overflow occurs iff the result has the opposite sign Subtraction rule: To subtract B from A, take the 2’s complement of B and add it to A [A - B = (A + (2’s complement of B))]

CE 454Ahmed Ezzat 12 DecimalSign 2’s Magnitude Complement DecimalSign 2’s Magnitude Complement Integer Data Representation: 2’s Complement Representation Conversion between 2’s complement and decimal: Awkward to humans, but very convenient for computers…

CE 454Ahmed Ezzat 13 Integer Data Representation: 2’s Complement Representation Conversion between 2’s complement and decimal: Value range for an n-bit number:  Positive Number Range: 0 ~ 2 n-2  Negative Number Range: -1 ~ -2 n-1 Example: for 4-bit number, value range (7  0)  (-1  -8)

CE 454Ahmed Ezzat 14 Integer Data Representation: 2’s Complement Representation 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

CE 454Ahmed Ezzat 15 Integer Arithmetic Operations Negation: Sign-magnitude: Invert the sign bit 2’s complement:  Invert each bit (including the sign bit)  Treat the result as unsigned binary integer, and add 1 Example: 7 (0111) to get -7 (( )  1001) -7 (1001) to get 7 (( )  0111)

CE 454Ahmed Ezzat 16 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 Integer Arithmetic Operations Addition and Subtraction

CE 454Ahmed Ezzat 17 To subtract one number (subtrahend) from another number minuend), take the twos complement (negation) of the subtrahend and add it to the minuend. (M - S) Overflow rule applies here also Integer Arithmetic Operations Subtraction

CE 454Ahmed Ezzat 18 Addition and Subtraction Hardware Block Diagram Integer Arithmetic Operations

CE 454Ahmed Ezzat 19 Integer Arithmetic Operations Multiplication: Unsigned binary integers

CE 454Ahmed Ezzat 20 Flowchart for unsigned binary multiplication Integer Arithmetic Operations: Multiplication

CE 454Ahmed Ezzat 21 Integer Arithmetic Operations Division: Unsigned binary integers

CE 454Ahmed Ezzat 22 Numbers with fractions Could be done in pure binary = – –3 = Where is the binary point  Fixed?  Very limited – can’t represent very large or very small numbers  Moving  How do you show where it is? Real Numbers

CE 454Ahmed Ezzat 23 Floating Point Representation Scientific notations: Slide the decimal point to a convenient location (left to decimal is a digit between 1 – 9 Keep track of the decimal point using an Exponent of 10 Do the same with binary numbers in the form of  Sign: + or -  Significant: S  Exponent: E

CE 454Ahmed Ezzat 24 Floating Point Representation Example 32-bit floating point format Leftmost bit = sign bit (0 positive and 1 negative) Exponent 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 Final portion of word (23 bits in this example) is the Significand (sometimes called Mantissa)

CE 454Ahmed Ezzat 25 Floating Point Representation Many ways to represent a floating point number - Example 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 Summary: (–1) sign  Significand)  2 Exponent – bias Left most bit always 1 –- no need to store 1-bit for sign, 8-bits for biased Exponent, 23-bits are used to store 24-bit Significand/Mantissa with a value 1  2

CE 454Ahmed Ezzat 26 Floating Point Representation Sign stored in the first bit Left most bit of the TRUE mantissa is always 1 – no need to store Bias of 127 for single precision and 1023 for double precision The value of 127 is added to the TRUE exponent to be stored (20  147) The base is 2

CE 454Ahmed Ezzat 27 Single Format and Double Format: Single Precision format:  32 bits, sign = 1 bit, Exponent = 8 bits, Mantissa = 23 bits  Numbers are normalised to form: ; where b = 0 or 1  Exponent formatted using excess-127 notation with implied base of 2  Theoretical Exponent range to  Actuality, Exponent values of 0 and 255 used for special values  Exponent range restricted to -126 to 127  0.0 defined by a Mantissa of 0 and the special Exponent value of 0  Allows + - infinity defined by a Mantissa value of 0 and Exponent value 255 Double Precision format:  64 bits, sign = 1 bit, Exponent = 11 bits, Mantissa = 52 bits Floating Point Representation: IEEE 754 Standard

CE 454Ahmed Ezzat 28 Floating Point Arithmetic Operations Addition and Subtraction: Check for zero Align the Significands Add or subtract the Significands Normalize the result:  E.g., x x x x 10 -1

CE 454Ahmed Ezzat 29

CE 454Ahmed Ezzat 30 Floating Point Representation Expressible Numbers: