Computer Organization and Architecture SCR 1043 Semester 2, 09/10 Tutorial: Arithmetic for Computers 1. Convert 409610 into a 32 bit two complement binary number. 2. Convert -204710 into a 32 bit two complement binary number. 3. What decimal number does this two complement binary number represent? i. 1111 1111 1111 1111 1111 1111 0000 0110 ii. 1111 1111 1111 1111 1111 1111 1110 1111 iii. 0111 1111 1111 1111 1111 1111 1110 1111 4. With x=0000 0000 0000 0000 0000 0000 0101 1011 and y=0000 0000 0000 0000 0000 0000 0000 1101 representing two complement signed integers, perform and show all work: i. x + y ii. x – y 5. Perform the same operations in question above 4 (a) and (b), but with x=1111 1111 1111 1111 1011 0011 0101 0011 and y=0000 0000 0000 0000 0000 0010 1101 0111 6. Perform the following arithmetic operations using two complement representations for the following 16 bit signed integers. i. 3010 + 1010 ii. 3010 – 1010 iii. 3010 - 4010 7. Create the table list for 1st Version of Multiplication Hardware Algorithm by multiplying 00102 by 01002. 8. Create the table list for 1st Version of Division Hardware Algorithm by dividing 0000 10112 by 01002. 9. Show IEEE 754 binary representation for the following floating point numbers in single and double precision. i. 2010 ii. 20.510 iii. 0.110 iv. Fraction –(5/6) v. Faction 1/64 vi. -15.010 1 10. We can mention that bits have no inherent meaning. Given the bit pattern: 1010 1101 0001 0000 0000 0000 0000 0010 What does is represent, assuming that it is: i. a two complement integer ii. an unsigned integer iii. a single precision floating point number 11. We can mention that bits have no inherent meaning. Given the bit pattern: 0010 0100 1001 0010 0100 1001 0010 0100 What does is represent, assuming that it is: i. a two complement integer ii. an unsigned integer iii. a single precision floating point number 12. Add 2.8510 x 103 to 9.8410 x 104, assuming that you have only 3 significant digits. 13. Add 3.6310 x 104 to 6.8710 x 103, assuming that you have only 3 significant digits. 14. Show how the following floating point calculations are performed (with significands are truncated to 4 decimal digits. Show the result in normalized form. i. (2.225 X 101) X (1.234 X 100) ii. (3.344 X 101) + (8.877 X 10-2) 15. With x=0100 0110 1101 1000 0000 0000 0000 0000 and y=1011 1110 1110 0000 0000 0000 0000 0000 representing single precision IEEE 754 floating point numbers, perform and show all work. i. x + y ii. x * y 16. The IEEE 754 floating point standard specifies 64 bit double precision with a 53 bit significand (including the implied 1) and an 11 bit exponent. IA 32 offers an extended precision option with a 64 bit significand and a 16 bit exponent. i. Assuming extended precision is similar to single and double precision, what is the bias in the exponent? ii. What is the range of numbers that can be represented by the extended precision option? 2 Computer Organization and Architecture SCR 1043 Semester 2, 08/09 Tutorial: Arithmetic for Computers 1. Convert 409610 into a 32 bit two complement binary number. 409610 = 00000000 00000000 00010000 000000002 2. Convert -204710 into a 32 bit two complement binary number. 204710 = 00000000 11111111 00000000 11111111 00000111 11111000 11111111 11111111 11111000 11111111 00000000 1+ 000000012 3. What decimal number does this two complement binary number represent? i. 11111111 11111111 11111111 00000110 00000000 00000000 00000000 00000000 -25010 00000000 00000000 = 11111001 1 111110102 ii. 11111111 11111111 11111111 11101111 00000000 00000000 00000000 00000000 -1710 00000000 00000000 = 00010000 1 000100012 iii. 01111111 11111111 11111111 11101111 = = 7F FF 214748363110 FF EF16 + + 4. With x = 00000000 00000000 00000000 01011011 and y = 00000000 00000000 00000000 00001101 representing two complement signed integers, perform and show all work: i. x + y + 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01011011 00001101 011010002 3 ii. x – y y= + -y = x -y 00000000 11111111 00000000 11111111 00000000 11111111 11111111 11111111 11111111 00001101 11110010 1 111100112 00000000 11111111 00000000 00000000 11111111 00000000 00000000 11111111 00000000 01011011 11110011 010011102 5. Perform the same operations in question above 4 (a) and (b), but with x = 11111111 11111111 10110011 01010011 and y = 00000000 00000000 00000010 11010111 (a) (b) x -y 11111111 00000000 11111111 11111111 00000000 11111111 10110011 00000010 10110110 01010011 11010111 001010102 00000000 11111111 00000000 11111111 00000010 11111101 11010111 00101000 11111111 11111111 11111101 1 001010012 11111111 11111111 11111111 11111111 11111111 11111111 10110011 11111101 10110000 01010011 00101001 011111002 + + + 6. Perform the following arithmetic operations using two complement representations for the following 16 bit signed integers. i. 3010 + 1010 00000000 00000000 00000000 00011110 00001010 001010002 + 3010 1010 4010 1010 + -1010 ii. 3010 – 1010 00000000 11111111 11111111 00001010 11110101 1 111101102 00000000 11111111 00000000 00011110 11110110 + 000101002 3010 1010 2010 4 iii. 3010 - 4010 00000000 11111111 11111111 00101000 11010111 1 110110002 00000000 11111111 11111111 00011110 11011000 + 111101102 4010 + -4010 3010 4010 -1010 7. Create the table list for 1st Version of Multiplication Hardware Algorithm by multiplying 00102 by 01002. Iteration Step Multiplier Multiplicand Product 0 1 Initial values 1:Mul0 =0; no operation 2:Shift left Multiplicand 3:Shift right Multiplier 1:Mul0 =0; no operation 2:Shift left Multiplicand 3:Shift right Multiplier 1a: Mul0 =1;Prod=Prod+Mcand 2:Shift left Multiplicand 3:Shift right Multiplier 1: Mul0 =0; no operation 2:Shift left Multiplicand 3:Shift right Multiplier 0100 0100 0100 0010 0010 0010 0001 0001 0001 0000 0000 0000 0000 0000 0010 0000 0010 0000 0100 0000 0100 0000 0100 0000 1000 0000 1000 0000 1000 0001 0000 0001 0000 0001 0000 0010 0000 0010 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1000 0000 1000 0000 1000 0000 1000 0000 1000 0000 1000 2 3 4 8. Create the table list for 1st Version of Division Hardware Algorithm by dividing 0000 10112 by 01002. Iteration 0 1 2 3 4 5 Step Initial values 1: Rem=Rem-Div 2b: Rem<0 => +Div, sli Q, Q0=0 3: Shift right Div 1: Rem=Rem-Div 2b: Rem<0 => +Div, sli Q, Q0=0 3: Shift right Div 1: Rem=Rem-Div 2b: Rem<0 => +Div, sli Q, Q0=0 3: Shift right Div 1: Rem=Rem-Div 2a: Rem>0 => sli Q, Q0=1 3: Shift right Div 1: Rem=Rem-Div 2b: Rem<0 => +Div, sli Q, Q0=0 3: Shift right Div Quotient 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 0001 0001 0010 0010 Divisor 0100 0000 0100 0000 0100 0000 0010 0000 0010 0000 0010 0000 0001 0000 0001 0000 0001 0000 0000 1000 0000 1000 0000 1000 0000 0100 0000 0100 0000 0100 0000 0010 Reminder 0000 1011 1100 1011 0000 1011 0000 1011 1110 1011 0000 1011 0000 1011 1111 1011 0000 1011 0000 1011 0000 0011 0000 0011 0000 0011 1111 1111 0000 0011 0000 0011 5 9. Show IEEE 754 binary representation for the following floating point numbers in single and double precision. i. 2010 (1) Convert to binary 2010 = 101002 = 1.0100 x 24 (2) Biased exponent single precision: 4+127 = 131 = 100000112 double precision: 4+1023 = 100 000000112 Single Precision Sign (1 bit) 0 Double Precision Sign (1 bit) 0 Exponent (11 bits) 10000000011 Exponent (8 bits) 10000011 Fraction (23 bits) 010000000000000000000000 Fraction (52 bits) 0100000000000000000000000000000000000000000000000000 ii. 20.510 (1) Convert to binary 20.510 = 10100.12 = 1.01001 x 24 (2) Biased exponent single precision: 4+127 = 131 = 100000112 double precision: 4+1023 = 100 000000112 Single Precision Sign (1 bit) 0 Double Precision Sign (1 bit) Exponent (11 bits) 0 10000000011 Exponent (8 bits) 10000011 Fraction (23 bits) 010010000000000000000000 Fraction (52 bits) 0100100000000000000000000000000000000000000000000000 iii. 0.110 (1) Convert to binary 0.110 = 0.000110011001100110011….. = 1.10011.. x 2-4 (2) Biased exponent single precision: -4+127 = 123 = 011110112 double precision: -4+1023 = 011 11111011 Single Precision Sign (1 bit) 0 Double Precision Sign (1 bit) 0 Exponent (11 bits) 01111111011 Exponent (8 bits) 01111011 Fraction (23 bits) 1001100110011001100110 Fraction (52 bits) 1001100110011001100110011001100110011001100110011001 6 iv. Fraction –(5/6) (1) Convert to binary 0.110 = 0.000110011001100110011….. = 1.010101010101010… x 216 (2) Biased exponent single precision: 16+127 = 143 = 100011112 double precision: -1+1023 = 1022 = 011 1111 1110 Single Precision Sign (1 bit) 1 Double Precision Sign (1 bit) 1 Exponent (11 bits) 11111111011 Exponent (8 bits) 10001111 Fraction (23 bits) 01010101010101010101010 Fraction (52 bits) 1001100110011001100110011001100110011001100110011001 v. Faction 1/64 (1) Convert to binary 1/6410 = 1 / 2-6= 0.000001 = 1.0 x 2-6 (2) Biased exponent single precision: -6+127 = 123 = 01111001 double precision: -6+1023 = 111 11111001 Single Precision Sign (1 bit) 0 Double Precision Sign (1 bit) 0 Exponent (11 bits) 11111111001 Exponent (8 bits) 01111011 Fraction (23 bits) 00000000000000000000000 Fraction (52 bits) 0000000000000000000000000000000000000000000000000000 vi. -15.010 (1) Convert to binary 15.010 = 1111.02 = 1.1110 x 23 (2) Biased exponent single precision: 3+127 = 130 = 10000010 double precision: 3 +1023 = 100 00000010 Single Precision Sign (1 bit) 0 Exponent (8 bits) 10000010 Fraction (23 bits) 11100000000000000000000 7 Double Precision Sign (1 bit) 0 Exponent (11 bits) 100 00000010 Fraction (52 bits) 1110000000000000000000000000000000000000000000000000 10. We can mention that bits have no inherent meaning. Given the bit pattern: 1010 1101 0001 0000 0000 0000 0000 0010 What does is represent, assuming that it is: i. a two complement integer 10101101 01010010 = 00010000 11101111 00000000 11111111 01010010 11101111 -1 391 460 35010 11111111 00000010 11111101 1 111111102 + ii. an unsigned integer 2 903 506 94610 iii. a single precision floating point number 1 01011010 001000000000000 00000010 sign = 1 exponent = 90 fraction = 0.00100000000000000000010 = 2-3 + 2-22 = 0.125000238 (-1)S x (1 + Fraction) x 2(Exponent – Bias) = (-1)1 x (1 + 0.125000238) x 2(90 – 127 = -1 x 1.125000238) = -8.185454048 x 10-12 11. We can mention that bits have no inherent meaning. Given the bit pattern: 0010 0100 1001 0010 0100 1001 0010 0100 What does is represent, assuming that it is: i. a two complement integer = 00100100 10010010 613 566 75610 01001001 00100100 ii. an unsigned integer 613 566 75610 8 iii. a single precision floating point number 0 01001001 00100100100100100100100 sign = 0 = +ve exponent = 10010012 = 73 fraction = 0.00100100100100100100100 = 2-3 + 2-6 +2-9 +2-3 +2-3 +2-3 +2-3 +2-3 + (-1)S x (1 + Fraction) x 2(Exponent – Bias) = (-1)0 x (1 + 0.142578125) x 273-127 = -1 x 1.142578125.. x …… = -6.34258 x 10-17 12. Add 2.8510 x 103 to 9.8410 x 104, assuming that you have only 3 significant digits. 2.8510 x 103 + 9.8410 x 104 (0.285 +9.84) x 104 10.125 x 104 1.01 x 105 13. Add 3.6310 x 104 to 6.8710 x 103, assuming that you have only 3 significant digits. (3.63 + 0.687) x 104 4.317 x 104 4.31 x 104 14. Show how the following floating point calculations are performed (with significands are truncated to 4 decimal digits. Show the result in normalized form. i. (2.225 X 101) X (1.234 X 100) (2.225 x 1.234) x 101+0 2.7456 x 101 ii. (3.344 X 101) + (8.877 X 10-2) (3.344 + 0.008877) x 101 3.3528 x 101 15. With x=0100 0110 1101 1000 0000 0000 0000 0000 and y=1011 1110 1110 0000 0000 0000 0000 0000 representing single precision IEEE 754 floating point numbers, perform and show all work. i. x + y 0 10111111 0111110 01000000 00000000 1 10111111 0111110 01000000 00000000 same number but different sign, the result is 0 9 ii. x * y 16. The IEEE 754 floating point standard specifies 64 bit double precision with a 53 bit significand (including the implied 1) and an 11 bit exponent. IA 32 offers an extended precision option with a 64 bit significand and a 16 bit exponent. i. Assuming extended precision is similar to single and double precision, what is the bias in the exponent? 216-1 – 1 = 32,767 ii. What is the range of numbers that can be represented by the extended precision option? 216-1 = 32768 log10 232768 = log10 a 32768(0.3) = log10 a 9820 = log10 a a =109864 Range of representation = 2.010 x 10-9864 ~ 2.010 x 109864 10