Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1."— Presentation transcript:

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

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

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

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

5 CE 454Ahmed Ezzat 5 Number Systems: Octal and Hexadecimal Octal: Base 8 number system – 0-7 – 345 o means 5 x 8 0 + 4 x 8 1 + 3 x 8 2 = 229 10 (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 2748 10 12 x 16 0 + 11 x 16 1 + 10 x 16 2 = 2748 Bytes (8 bits) are sometimes written in oct/hex for convenience

6 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 65 0100 0001 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.

7 CE 454Ahmed Ezzat 7 Integer Data Representation Representing arbitrary numbers Human: -1101.0101 2 = -13.3125 10 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

8 CE 454Ahmed Ezzat 8 An 8-bit can represent the numbers from 0 -255 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:

9 CE 454Ahmed Ezzat 9                   0 if 2 1 2 2 0 2 0 n-1 n i i i n i i i bbA bbA A +18 = 00010010 -18 = 10010010 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

10 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 = 00000000  -0 = 10000000

11 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))]

12 CE 454Ahmed Ezzat 12 DecimalSign 2’s Magnitude Complement ------------------------------------------------------- +701110111 +601100110 +501010101 +401000100 +300110011 +200100010 +100010001 +000000000 DecimalSign 2’s Magnitude Complement ------------------------------------------------------ -010000000 -110011111 -210101110 -310111101 -411001100 -511011011 -611101010 -711111001 -8 ----- 1000 Integer Data Representation: 2’s Complement Representation Conversion between 2’s complement and decimal: Awkward to humans, but very convenient for computers…

13 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)

14 CE 454Ahmed Ezzat 14 Integer Data Representation: 2’s Complement Representation Conversion between different bit lengths: +18 = 00010010(sign magnitude, 8-bit) +18 = 0000000000010010(sign magnitude, 16-bit) -18 = 10010010(sign magnitude, 8-bit) -18 = 1000000000010010(sign magnitude, 16-bit) +18 = 00010010(twos complement, 8-bit) +18 = 0000000000010010(twos complement, 16-bit) -18 = 11101110(twos complement, 8-bit) -18 = 1111111111101110 (twos complement, 16-bit) Fixed point Representation

15 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 ((1000 + 1)  1001) -7 (1001) to get 7 ((0110 + 1)  0111)

16 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

17 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

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

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

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

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

22 CE 454Ahmed Ezzat 22 Numbers with fractions Could be done in pure binary 1001.1010 = 2 3 + 0 + 0 + 2 0 + 2 –1 + 0 + 0 + 2 –3 = 9.625 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

23 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

24 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-1 - 1. (The bias could take other values). In this case: 8-bit Exponent field, 0 - 255. Bias = 127. Exponent range -127 to +128 Final portion of word (23 bits in this example) is the Significand (sometimes called Mantissa)

25 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

26 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

27 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 2 -127 to 2 128  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

28 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., 0.5566 x 10 3 + 0.7778 x 10 3 0.5323 x 10 2 + 0.7268 x 10 -1

29 CE 454Ahmed Ezzat 29

30 CE 454Ahmed Ezzat 30 Floating Point Representation Expressible Numbers:


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

Similar presentations


Ads by Google