Conversion to Larger Number of Bits Ex Immediate
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number in right most 16 bits and fill with 0’s.
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number in right most 16 bits and fill with 0’s. 0011 1101 0010 0000 0011 1101 0010
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number in right most 16 bits and fill with 0’s. Negative numbers have implied 1’s to the left because it’s the complement of a positive number’s 0’s. So, put 16 bit number in right most 16 bits and fill with 1’s.
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number in right most 16 bits and fill with 0’s. Negative numbers have implied 1’s to the left because it’s the complement of a positive number’s 0’s. So, put 16 bit number in right most 16 bits and fill with 1’s. 1100 1110 1010 1111 1100 1110 1010 1110
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number in right most 16 bits and fill with 0’s. Negative numbers have implied 1’s to the left because it’s the complement of a positive number’s 0’s. So, put 16 bit number in right most 16 bits and fill with 1’s. Or, put 16 bits in the right most 16 bits and fill with the sign bit. This is called sign extension.
Division – Positive numbers Quotient Divisor 0010 00000111 Dividend
Division – Positive numbers Trial 1 Quotient Divisor 0010 00000111 Dividend or Remainder 1110 < 0 Change Quotient bit to 0 and restore This must be true or the quotient would exceed 4 bits, so start with shift
Division – Positive numbers Trial 1 Quotient Divisor 0010 00000111 Dividend or Remainder 1110 < 0 Change Quotient bit to 0 and restore, then shift and try again
Division – Positive numbers Trial 01 Quotient Divisor 0010 00000111 Dividend or Remainder 1110 1111 < 0 Change Quotient bit to 0 and restore, then shift and try again
Division – Positive numbers Trial 001 Quotient Divisor 0010 00000111 Dividend or Remainder 1110 0001 > 0 shift and use new remainder
Division – Positive numbers Trial 001 Quotient Divisor 0010 00000111 1110 00011 Dividend or Remainder New Remainder
Division – Positive numbers Trial 0011 Divisor 0010 00000111 1110 0001 Quotient Dividend or Remainder
Same basic hardware as Multiply Divisor 0010 00000111 4 bit ALU Remainder 00000111 Control Test Shift R / L Initialize with Dividend 0111
1. Shift Remainder left Divisor 0010 00000111 4 bit ALU Remainder 00000111 Control Test Shift R / L Dividend 0111
2’s complement 1110 1. Shift Remainder left 2. Subtract the Divisor 0010 00000111 1110 4 bit ALU Remainder 00001110 Control Test Shift R / L Dividend 0111
1. Shift Remainder left 2. Subtract the Divisor 3. < 0, add Divisor 1110 0010 00000111 1110 0010 4 bit ALU Remainder 1110 Control Test Shift R / L Dividend 0111
1. 2. 3. 4. Divisor 1110 0010 Shift Remainder left Subtract the Divisor < 0, add Divisor Shift left, Set 0 4 bit ALU Remainder 00001110 Control Test Shift R / L Dividend 0111 0010 00000111 1110 0010 0000
1. Subtract the Divisor 1110 0010 00000111 1110 4 bit ALU Remainder 00011100 Control Test Shift R / L Dividend 0111
1. Subtract the Divisor 2. < 0, add Divisor 1110 0010 00000111 1110 1111 0010 4 bit ALU Remainder 11111100 Control Test Shift R / L Dividend 0111
1. Subtract the Divisor 2. < 0, add Divisor 3. Shift, Set 0 Divisor 1110 0010 4 bit ALU Remainder 00011100 0 0010 00000111 1110 1111 0010 Control 0001 Test Shift R / L Dividend 0111
1. Subtract the Divisor 1110 00 0010 00000111 1110 4 bit ALU Remainder 00111000 Control Test Shift R / L Dividend 0111
1. Subtract the Divisor 2. >0, shift left, set 1 Divisor 1110 00 0010 00000111 1110 0001 4 bit ALU Remainder 00011000 Control Test Shift R / L Dividend 0111
1. Subtract the Divisor 1110 001 0010 00000111 1110 00011 1110 4 bit ALU Remainder 00110001 Control Test Shift R / L Dividend 0111
1. Subtract the Divisor 2. >0, Shift left, set 1 Divisor 1110 0010 4 bit ALU Remainder 0001 0010 00000111 1110 00011 1110 Control 0001 Test Shift R / L Dividend 0111
1. Subtract the Divisor 2. >0, Shift left, set 1 3. Shift left half right Divisor 1110 0010 4 bit ALU Remainder 00100011 0010 00000111 1110 00011 1110 Control 00010 Test Shift R / L Dividend 0111
Quotient = 0011 Remainder = 0001 Divisor 1110 0010 4 bit ALU Remainder 00010011 0010 00000111 1110 00011 1110 Control 0001 Test Shift R / L Dividend 0111
Non-Restoring Division r = Remainder d = Divisor r – d < 0, Qi = 0, restore, shift and subtract Divisor
Non-Restoring Division r = Remainder d = Divisor r – d < 0, Qi = 0, restore, shift and subtract Divisor (r – d + d)*2 – d = (r – d)*2 + 2 d – d = ( r – d)*2 + d
Non-Restoring Division r = Remainder d = Divisor r – d < 0, Qi = 0, restore, shift and subtract Divisor (r – d + d)*2 – d = (r – d)*2 + 2 d – d = ( r – d)*2 + d If r – d < 0, Qi = 0, shift r-d and add Divisor
Non-Restoring Division r = Remainder d = Divisor r – d < 0, Qi = 0, restore, shift and subtract Divisor (r – d + d)*2 – d = (r – d)*2 + 2 d – d = ( r – d)*2 + d If r – d < 0, Qi = 0, shift r-d and add Divisor Algorithm for Non- restoring Division 1. Subtract Divisor from Remainder 2. If r-d > = 0, Qi = 1, shift and subtract divisor 3. If r-d < 0, Qi =0, shift and add divisor 4. After n bits, if Remainder is negative, restore
Non –Restoring Division 1. Shift Remainder Register left 1 bit 2. Subtract the Divisor Register from the left half of the Remainder Register Test Remainder >= 0 3 a. Shift Remainder left and set bit 0 to 1 n Repetitions ? Yes No 4 a. Subtract Divisor from left half of Remainder Register 5 a. Shift left half of Reminder right one bit <0 3 b. Shift Remainder left and set bit 0 to 0 Yes n Repetitions ? No 4 b. Add Divisor to left half of Remainder Register 5 b. Shift left half of Remainder right one bit and add Divisor to left half of Remainder
Non –Restoring Division Divisor 0010 00000111 4 bit ALU Remainder 00000111 Control Test Shift R / L Initialize with Dividend 0111
1. Shift Remainder left Divisor 0010 00000111 4 bit ALU Remainder 00000111 Control Test Shift R / L Dividend 0111
2’s complement 1110 1. Shift Remainder left 2. Subtract the Divisor 0010 00000111 1110 4 bit ALU Remainder 00001110 Control Test Shift R / L Dividend 0111
2’s complement 1110 1. Shift Remainder left 2. Subtract the Divisor 3. < 0, Shift left, Set 0 Divisor 0010 00000111 1110 4 bit ALU Remainder 1110 Control Test Shift R / L Dividend 0111
2’s Complement 1. Add divisor Divisor 1110 0010 00000111 11101 4 bit ALU Remainder 11011110 Control Test Shift R / L Dividend 0111
2’s Complement 1. Add divisor Divisor 1110 0010 00000111 11101 0010 4 bit ALU Remainder 11011110 Control Test Shift R / L Dividend 0111
2’s Complement 1. Add divisor 2. < 0, Shift left, set 0 Divisor 1110 0010 4 bit ALU Remainder 11111110 Control Test Shift R / L Dividend 0111 0 0010 00000111 11101 0010 1111
2’s Complement 1. Add divisor Divisor 1110 0010 4 bit ALU Remainder 11111100 Control Test Shift R / L Dividend 0111 00 0010 00000111 11101 0010 11111 0010
2’s Complement 1. Add divisor 2. > 0, Shift left, set 1 Divisor 1110 0010 4 bit ALU Remainder 00011100 Control Test Shift R / L Dividend 0111 00 0010 00000111 11101 0010 11111 0010 0001
2’s Complement 1. Subtract divisor Divisor 1110 0010 4 bit ALU Remainder 00111001 Control Test Shift R / L Dividend 0111 0010 00000111 11101 0010 11111 0010 00011 1110
2’s Complement 1. Subtract divisor 2. >0, Shift left, set 1 Divisor 1110 0010 4 bit ALU Remainder 00011001 Control Test Shift R / L Dividend 0111 0010 00000111 11101 0010 11111 0010 00011 1110 0001
2’s Complement 1. Subtract divisor 2. >0, Shift left, set 1 3. Shift Left Half right Divisor 1110 0010 4 bit ALU Remainder 0011 Control Test Shift R / L Dividend 0111 0010 00000111 11101 0010 11111 0010 00011 1110 0001
2’s Complement 1. Subtract divisor 2. >0, Shift left, set 1 3. Shift Left Half right Divisor 1110 0010 4 bit ALU Remainder 00010011 Control Test Shift R / L Dividend 0111 0010 00000111 11101 0010 11111 0010 00011 1110 0001
MIPS Instructions for Multiply and Divide Hi, Lo are two 32 bit registers for Product and Remainder divide div $s 1, $s 2 # Lo = $s 1/$s 2 = quotient # Hi = $s 1 mod$s 2 = remainder For signed numbers, 1. determine the sign of the quotient 2. convert to positive representation 3. divide 4. determine the sign and convert to 2’s complement if needed
MIPS Instructions for Multiply and Divide Hi, Lo are two 32 bit registers for Product and Remainder divide div $s 1, $s 2 divide unsigned divu $s 1, $s 2 # Lo = $s 1/$s 2 = quotient # Hi = $s 1 mod$s 2 = remainder # unsigned version of div
MIPS Instructions for Multiply and Divide Hi, Lo are two 32 bit registers for Product and Remainder multiply mult $s 1, $s 2 # Hi, Lo = $s 1 x $s 2 multiply unsigned multu $s 1, $s 2 # Hi, Lo = $s 1 x $s 2 ( unsigned) move from Hi mfhi $s 3 # $s 3 = Hi move from Lo mflo $s 3 # $s 3 = Lo
Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as shift k to the right, 0 fill
Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as shift k to the right, 0 fill For 2’s Complement Numbers It does not always work!
Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as shift k to the right, 0 fill For 2’s Complement Numbers It does not always work! Ex: -5 = -0101 , 2’s Complement = 1011 Divide by 4 by shift right 2, fill with ?
Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as shift k to the right, 0 fill For 2’s Complement Numbers It does not always work! Ex: -5 = -0101 , 2’s Complement = 1011 Divide by 4 by shift right 2, fill with ? 1110 is 0001+1=0010 = 2 WRONG!
Floating Point Numbers Normalized Mantissa or Significand Exponent Add 0. 713 x 10 -2 and 0. 964 x 10 -1
Floating Point Numbers Normalized Mantissa or Significand Exponent Add 0. 713 x 10 -2 and 0. 964 x 10 -1 1. Align the exponents by shifting the smaller 0. 0713 x 10 -1 0. 9640 x 10 -1
Floating Point Numbers Normalized Mantissa or Significand Exponent Add 0. 713 x 10 -2 and 0. 964 x 10 -1 1. Align the exponents by shifting the smaller 0. 0713 x 10 -1 0. 9640 x 10 -1 2. Add 1. 0353 x 10 -1
Floating Point Numbers Add 0. 713 x 10 -2 and 0. 964 x 10 -1 1. Align the exponents by shifting the smaller 0. 0713 x 10 -1 0. 9640 x 10 -1 2. Add 1. 0353 x 10 -1 3. Normalize 0. 10353 x 100
Floating Point Numbers Add 0. 713 x 10 -2 and 0. 964 x 10 -1 1. Align the exponents by shifting the smaller 0. 0713 x 10 -1 0. 9640 x 10 -1 2. Add 1. 0353 x 10 -1 3. Normalize 0. 10353 x 100 4. Round off 0. 104 x 100
Normalized REAL Binary Number: ± 1. yyyyy x 2 eeee
Normalized REAL Binary Number: ± 1. yyyyy x 2 eeee Leading 1 Binary Point Significand = 1. yyyyy Exponent(signed) Arithmetic
Normalized REAL Binary Number: ± 1. yyyyy x 2 eeee Leading 1 Binary Point Significand = 1. yyyyy Exponent(signed) Arithmetic
Floating Point Numbers Add 1. 0101 x 23 and 1. 1011 x 21
Floating Point Numbers Add 1. 0101 x 23 and 1. 1011 x 21 1. Align the exponents by shifting the smaller 1. 0101 x 23 0. 011011 x 23
Floating Point Numbers Add 1. 0101 x 23 and 1. 1011 x 21 1. Align the exponents by shifting the smaller 1. 0101 x 23 0. 011011 x 23 2. Add 1. 101111 x 23
Floating Point Numbers Add 1. 0101 x 23 and 1. 1011 x 21 1. Align the exponents by shifting the smaller 1. 0101 x 23 0. 011011 x 23 2. Add 1. 101111 x 23 3. Normalize – Check for Overflow and Underflow 1. 101111 x 23
Round - Off 4. 56 +. 0357 4. 5957 3 significant digits
Round - Off 4. 56 +. 0357 4. 5957 3 significant digits 4. 60 Rounded Off
Round - Off 4. 56 +. 0357 4. 5957 3 significant digits 4. 60 Rounded Off What if 4. 5950 ?
Round - Off 4. 56 +. 0357 4. 5957 3 significant digits 4. 60 Rounded Off What if 4. 5950 ? 4. 60 Round to even
Round - Off Binary. 00. 01. 10. 11 Decimal. 00. 25. 50. 75
Round - Off Binary. 00. 01. 10. 11 Decimal. 00. 25. 50 Are there any trailing 1’s ? If not, round to even. 75
Floating Point Numbers Add 1. 0101 x 23 and 1. 1011 x 21 1. Align the exponents by shifting the smaller 1. 0101 x 23 0. 011011 x 23 2. Add 1. 101111 x 23 3. Normalize – Check for Overflow and Underflow 1. 101111 x 23 4. Round to 4 bits Guard bit = 1 and Round bit = 1
Floating Point Numbers Add 1. 0101 x 23 and 1. 1011 x 21 1. Align the exponents by shifting the smaller 1. 0101 x 23 0. 011011 x 23 2. Add 1. 101111 x 23 3. Normalize – Check for Overflow and Underflow 1. 101111 x 23 4. Round to 4 bits Guard bit = 1 and Round bit = 1 1. 1100 x 23
IEEE 754 Floating Point Standard Normalized REAL Binary Number: ± 1. yyyyy x 2 eeee IEEE 754 (-1)S x ( 1 + F) x 2 E-127 s exponent+127 1 bit E (8 bits) significand - 1 F (23 bits)
IEEE 754 Floating Point Standard Normalized REAL Binary Number: ± 1. yyyyy x 2 eeee IEEE 754 (-1)S x ( 1 + F) x 2 E-127 s exponent+127 1 bit E (8 bits) Bias Exponent E>0 significand - 1 F (23 bits)
IEEE 754 Floating Point Standard Normalized REAL Binary Number: ± 1. yyyyy x 2 eeee IEEE 754 (-1)S x ( 1 + F) x 2 E-127 s exponent+127 1 bit E (8 bits) significand - 1 F (23 bits) • Only Zero is F = 0 and E = 0 • Simplifies data exchange • Compare using integer processes • Accuracy and round-off & Overflow and Underflow
IEEE 754 Floating Point Standard 1 10000010 01010000000000 =. 25+. 0625 =. 3125
IEEE 754 Floating Point Standard 1 10000010 01010000000000 =. 25+. 0625 =. 3125 E = 27 + 2 = 128 + 2 = 130
IEEE 754 Floating Point Standard 1 10000010 01010000000000 =. 25+. 0625 =. 3125 E = 27 + 2 = 128 + 2 = 130 Number = (-1)S x ( 1 + F) x 2 E-127
IEEE 754 Floating Point Standard 1 10000010 01010000000000 =. 25+. 0625 =. 3125 E = 27 + 2 = 128 + 2 = 130 Number = (-1)S x ( 1 + F) x 2 E-127 = – ( 1 +. 3125) x 2130 – 127
IEEE 754 Floating Point Standard 1 10000010 01010000000000 =. 25+. 0625 =. 3125 E = 27 + 2 = 128 + 2 = 130 Number = (-1)S x ( 1 + F) x 2 E-127 = – ( 1 +. 3125) x 2130 – 127 = – 1. 3125 x 23 = – 1. 3125 x 8 = – 10. 5
IEEE 754 Floating Point Standard Consider representing – 5 in IEEE 754 Floating Point Format
IEEE 754 Floating Point Standard Consider representing – 5 in IEEE 754 Floating Point Format 5 = 101. 0 x 20 = 1. 01 x 22
IEEE 754 Floating Point Standard Consider representing – 5 in IEEE 754 Floating Point Format 5 = 101. 0 x 20 = 1. 01 x 22 IEEE 754 (-1)S x ( 1 + F) x 2 E-127 s exponent+127 1 bit E (8 bits) significand - 1 F (23 bits)
IEEE 754 Floating Point Standard Consider representing – 5 in IEEE 754 Floating Point Format 5 = 101. 0 x 20 = 1. 01 x 22 IEEE 754 (-1)S x ( 1 + F) x 2 E-127 s exponent+127 1 bit significand - 1 E (8 bits) E – 127 = 2 E = 2 + 127 = 129 = 1000 0001 F (23 bits)
IEEE 754 Floating Point Standard Consider representing – 5 in IEEE 754 Floating Point Format 5 = 101. 0 x 20 = 1. 01 x 22 IEEE 754 (-1)S x ( 1 + F) x 2 E-127 s exponent+127 1 bit significand - 1 E (8 bits) E – 127 = 2 E = 2 + 127 = 129 = 1000 0001 1 +F = 1. 01000. . . F (23 bits)
IEEE 754 Floating Point Standard Consider representing – 5 in IEEE 754 Floating Point Format 5 = 101. 0 x 20 = 1. 01 x 22 IEEE 754 (-1)S x ( 1 + F) x 2 E-127 s exponent+127 1 bit significand - 1 E (8 bits) F (23 bits) E = 2 + 127 = 129 = 1000 0001 1 +F = 1. 01000. . . 1 1000 0001 0100 0000. . 0000
IEEE 754 Floating Point Standard Normalized REAL Binary Number: ± 1. yyyyy x 2 eeee Double Precision IEEE 754 (-1)S x ( 1 + F) x 2 E-1023 s exponent+1023 1 bit significand - 1 E (11 bits) F (20 bits) significand – 1 (continued) F (32 bits)
- Slides: 87