Presentation is loading. Please wait.

Presentation is loading. Please wait.

COE 308: Computer Architecture (T032) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (cont.) (Appendix A, Computer Architecture: A Quantitative.

Similar presentations


Presentation on theme: "COE 308: Computer Architecture (T032) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (cont.) (Appendix A, Computer Architecture: A Quantitative."— Presentation transcript:

1 COE 308: Computer Architecture (T032) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (cont.) (Appendix A, Computer Architecture: A Quantitative Approach, J. Hennessy & D. Patterson, 1 st Edition, 1990)

2 Saturday, April 03, 2004 COE 308 (T032) – Dr. Marwan Abu-Amara 2 Radix-2 Multiplication & Division Signed Numbers Multiplication: To perform 2’s complement multiplication, use same algorithm as before but with the following modifications: 1. At the i th multiply step, LSB of A is a i, and: for 1 st step (i.e. when i = 0), take a i-1 to be 0 2. Shift P arithmetically (i.e. copy sign bit) 1 bit to right If a i =& a i-1 =then 00Add 0 to P 01Add B to P 10Sub B from P 11Add 0 to P

3 Saturday, April 03, 2004 COE 308 (T032) – Dr. Marwan Abu-Amara 3 Example 1 of Multiplication Multiply -6 by -5  A = -6 = a 3 a 2 a 1 a 0 = 1010 2 & B = -5 = 1011 2 Iteration Step P A a i-1 0000 1010 0 +01 +0000 0 0000 1010 2 0000 0101 0 -B1 +0101 1 0101 0101 2 0010 1010 1 +B1 +1011 2 1101 1010 2 1110 1101 0 -B1 +0101 3 0011 1101 2 0001 1110 1  Product = P & A = +30

4 Saturday, April 03, 2004 COE 308 (T032) – Dr. Marwan Abu-Amara 4 Example 2 of Multiplication Multiply -6 by +5  A = -6 = a 3 a 2 a 1 a 0 = 1010 2 & B = +5 = 0101 2 Iteration Step P A a i-1 0000 1010 0 +01 +0000 0 0000 1010 2 0000 0101 0 -B1 +1011 1 1011 0101 2 1101 1010 1 +B1 +0101 2 0010 1010 2 0001 0101 0 -B1 +1011 3 1100 0101 2 1110 0010 1  Product = P & A = -30

5 Saturday, April 03, 2004 COE 308 (T032) – Dr. Marwan Abu-Amara 5 Floating Point A floating-point number (FP #) is divided into 2 parts: 1. Exponent 2. Significand (or Mantissa) FP # = significand  base exponent (e.g. exponent = -2 & significand = 1.5  FP # = 1.5  2 -2 = 0.375) Single-precision # is represented using 32 bits: 1 for sign 8 for exponent 23 for fraction Exponent is a signed # represented using the bias method with a bias of 127 Significand = Mantissa = 1 + fraction Thus, if e = value of exponent field, and f = value of fraction field, then FP # represented is 1.f  2 e–127

6 Saturday, April 03, 2004 COE 308 (T032) – Dr. Marwan Abu-Amara 6 Floating Point (cont.) Example: What single-precision FP # does the following 32-bit word represent? 1100000010100…00 1 10000001 0100…00  sign = 1 = –ve exponent field = e = 10000001 2 = 129 (  exponent = 129–127 = 2) fraction field = f =.0100…00 2 = 0.01 2 = 0.25  FP # = –1.f  2 e–127 = –1.25  2 129–127 = –1.25  4 = –5 Range of exponent field (i.e. e) is from 1 to 254 (i.e. exponent is from –126 to 127)  e = 0 or 255 are used to represent special values

7 Saturday, April 03, 2004 COE 308 (T032) – Dr. Marwan Abu-Amara 7 Floating Point (cont.) efFP # RepresentedComment 255= 0  255  0 NaNNot a Number 0= 00 0  0 denormal # (or subnormal #) Deals with very small values

8 Saturday, April 03, 2004 COE 308 (T032) – Dr. Marwan Abu-Amara 8 Floating Point Addition What is the sum of 1,234,823.333 &.0011?  Need to line up the decimal points first  This is the same as shifting the significand while changing the exponents 1,234,823.333 = 1.234823333  10 6.0011 = 1.1  10 -3 = 0.0000000011  10 6  Add significands (using integer addition) Significand sum= 1.234823333 + 0.0000000011 = 1.2348233341  Normalize the result, if needed Result = 1.2348233341  10 6

9 Saturday, April 03, 2004 COE 308 (T032) – Dr. Marwan Abu-Amara 9 Floating Point Addition (cont.) Binary FP Addition Algorithm:  Similar to decimal FP addition method  Let e i = exponent, s i = significand (i.e. 1 + f i = 24 bits), then steps of algorithm are: 1. If e 1 < e 2, swap the operands, calculate d = e 1 – e 2 (note that d  0), and set exponent of result to e 1 2. Shift s 2 by d places to the right 3. Add s 1 & result of step 2, and store result in s 1 4. Normalize:  If result of step 3 (i.e. s 1 )  2  Shift s 1 by 1 place right & add 1 to exponent  If s 1 < 1  Shift s 1 to left until leftmost binary digit is 1 & subtract # of shifts from exponent  If s 1 = 0  Load special zero pattern into exponent  Otherwise, do nothing (i.e. done)


Download ppt "COE 308: Computer Architecture (T032) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (cont.) (Appendix A, Computer Architecture: A Quantitative."

Similar presentations


Ads by Google