Data Representation and Arithmetic Algorithms Module II Data Representation and Arithmetic Algorithms
Non-Restoring Division
END A A + M START A 0 M Divisor Q Dividend Count n A < 0? Yes No Shift Left A,Q A A - M A A + M Q0 = 0 Count =0? Count Count -1 Q0 = 1
10 / 3 A Q Cnt 0000 1010 4 M 0011 START Initial values A 0 M Divisor END A A + M START A 0 M Divisor Q Dividend Count n A < 0? Yes No Shift Left A,Q A A - M A A + M Q0 = 0 Count =0? Count Count -1 Q0 = 1 10 / 3 A Q Cnt 0000 1010 4 Initial values M 0011
10 / 3 A Q Cnt 0000 1010 4 0001 0100 M 0011 START Initial values A 0 END A A + M START A 0 M Divisor Q Dividend Count n A < 0? Yes No Shift Left A,Q A A - M A A + M Q0 = 0 Count =0? Count Count -1 Q0 = 1 10 / 3 A Q Cnt 0000 1010 4 Initial values 0001 0100 Shift M 0011
10 / 3 A Q Cnt 0000 1010 4 0001 0100 1110 M 0011 START Initial values END A A + M START A 0 M Divisor Q Dividend Count n A < 0? Yes No Shift Left A,Q A A - M A A + M Q0 = 0 Count =0? Count Count -1 Q0 = 1 10 / 3 A Q Cnt 0000 1010 4 Initial values 0001 0100 Shift 1110 A - M M 0011
END A A + M START A 0 M Divisor Q Dividend Count n A < 0? Yes No Shift Left A,Q A A - M A A + M Q0 = 0 Count =0? Count Count -1 Q0 = 1 A Q Cnt 0000 1010 4 Initial values 0001 0100 Shift 1110 A – M 3 Q0 = 0 M 0011 10 / 3
END A A + M START A 0 M Divisor Q Dividend Count n A < 0? Yes No Shift Left A,Q A A - M A A + M Q0 = 0 Count =0? Count Count -1 Q0 = 1 A Q Cnt 0000 1010 4 Initial values 0001 0100 Shift 1110 A – M 3 Q0 = 0 1100 1000 1111 A + M M 0011 10 / 3
END A A + M START A 0 M Divisor Q Dividend Count n A < 0? Yes No Shift Left A,Q A A - M A A + M Q0 = 0 Count =0? Count Count -1 Q0 = 1 A Q Cnt 0000 1010 4 Initial values 0001 0100 Shift 1110 A – M 3 Q0 = 0 1100 1000 1111 A + M 2 M 0011 10 / 3
END A A + M START A 0 M Divisor Q Dividend Count n A < 0? Yes No Shift Left A,Q A A - M A A + M Q0 = 0 Count =0? Count Count -1 Q0 = 1 A Q Cnt 0000 1010 4 Initial values 0001 0100 Shift 1110 A – M 3 Q0 = 0 1100 1000 1111 A + M 2 0010 M 0011 10 / 3
END A A + M START A 0 M Divisor Q Dividend Count n A < 0? Yes No Shift Left A,Q A A - M A A + M Q0 = 0 Count =0? Count Count -1 Q0 = 1 A Q Cnt 0000 1010 4 Initial values 0001 0100 Shift 1110 A – M 3 Q0 = 0 1100 1000 1111 A + M 2 0010 1 Q0 = 1 M 0011 10 / 3
END A A + M START A 0 M Divisor Q Dividend Count n A < 0? Yes No Shift Left A,Q A A - M A A + M Q0 = 0 Count =0? Count Count -1 Q0 = 1 A Q Cnt 0000 1010 4 Initial values 0001 0100 Shift 1110 A – M 3 Q0 = 0 1100 1000 1111 A + M 2 0010 1 Q0 = 1 A - M M 0011 10 / 3
END A A + M START A 0 M Divisor Q Dividend Count n A < 0? Yes No Shift Left A,Q A A - M A A + M Q0 = 0 Count =0? Count Count -1 Q0 = 1 A Q Cnt 0000 1010 4 Initial values 0001 0100 Shift 1110 A – M 3 Q0 = 0 1100 1000 1111 A + M 2 0010 1 Q0 = 1 0011 M 0011 10 / 3
Floating Point Arithmetic
Addition and Subtraction Phase 1: Zero check. The process begins by changing the sign of the subtrahend if it is a subtract operation. If either operand is 0, the other is reported as result. Phase 2: Significand alignment. This phase manipulate the numbers so that the two exponents are equal.
Addition and Subtraction Phase 3: Addition The two significands are added together, taking into account their signs. If there is significand overflow by 1 digit,the result is shifted right and the exponent is incremented. If exponent overflow occurs, this will be reported. Phase 4: Normalization. It consists of shifting significand digits left until the most significant digit is nonzero.
Example : Floating Point Adder Unit
Floating Point Adder Unit The inputs to adder are two normalized floating point numbers of the form A = a x 10p B = b x 10q where a and b are two fractions and p and q are their exponents.
Floating Point Adder Unit Our purpose is to compute the sum C = A + B = c x 10r = d x 10s where r = max(p,q) and 0.1 ≤ d < 1 For example: A=0.9504 x 103 B=0.8200 x 102 a = 0.9504 b= 0.8200 p=3 & q =2
Floating Point Adder Unit Operations performed are : Compare p and q and choose the largest exponent, r = max(p,q)and compute t = |p – q| Example: r = max(p , q) = 3 t = |p-q| = |3-2|= 1
Floating Point Adder Unit Shift right the fraction associated with the smaller exponent by t units to equalize the two exponents before fraction addition. Example: Smaller exponent, b= 0.8200 Shift right b by 1 unit is 0.082
Floating Point Adder Unit Perform fixed-point addition of two fractions to produce the intermediate sum fraction c Example : a = 0.9504 b= 0.082 c = a + b = 0.9504 + 0.082 = 1.0324
Floating Point Adder Unit Count the number of leading zeros (u) in fraction c and shift left c by u units to produce the normalized fraction sum d = c x 10u, with a leading bit 1. Update the large exponent s by subtracting s = r – u to produce the output exponent. Example: c = 1.0324 , u = -1 right shift d = 0.10324 , s= r – u = 3-(-1) = 4 C = 0.10324 x 104
Floating Point Adder Unit The above 4 steps can all be implemented with combinational logic circuits and the 4 stages are: Comparator / Subtractor Shifter Fixed Point Adder Normalizer (leading zero counter and shifter)
Example for floating-point adder Exponents Segment 1: Segment 2: Segment 3: Segment 4: R Adjust exponent Normalize result Add mantissas Align mantissas Choose exponent Compare exponents by subtraction Difference=3-2=1 Mantissas b a A B For example: X=0.9504*103 Y=0.8200*102 0.082 3 S=0.9504+0.082=1.0324 0.10324 -1
4-STAGE FLOATING POINT ADDER A = a x 2 p B = b x 2 q a b A B Exponent subtractor Fraction selector Fraction with min(p,q) Right shifter Other fraction t = |p - q| r = max(p,q) adder Leading zero counter r c Left shifter s d Stages: S1 S2 S3 S4 C= X + Y = d x 2s
Problem Using Non-Restoring division algorithm perform 1011/0101