ALU (3) - Division Algorithms: Humboldt-Universität Zu Berlin
ALU (3) - Division Algorithms: Humboldt-Universität Zu Berlin
INSTITUT FR INFORMATIK
Lecture 12
CA - XII - ALU(3) - 1
B. FLOATING-POINT ARITHMETIC
FORMATS ADDITION/SUBTRACTION MULTIPLICATION/DIVISION
C. LOGIC FUNCTIONS
CA - XII - ALU(3) - 2
QUOTIENT SETTING
ADD/SUBTRACT
CONTROL LOGIC
mn-1
m0
DIVISOR M
CA - XII - ALU(3) - 3
STOP
Quotient in Q
CA - XII - ALU(3) - 4
Remainder in A
A R E S T O R I N G D I V I S I O N E X A M P L E
Initially Shift Substract Set LSB Restore Shift Subtract Set LSB Restore Shift Subtract Set LSB Shift Subtract Set LSB Restore
A M
00000 00011 00001 11101 11110 11 00001 00010 11101 11111 11 00010 00100 11101 0 0 0001 00010 11101 11111 11 00010
1000 000
000 0 000 0 0 0 0 0 0 0 0 0 0 0 1 0 1
NONRESTORING DIVISION
ALGORITHM FOR NONRESTORING DIVISION STEP 1: DO n TIMES
IF THE SIGN OF A IS 0, SHIFT A AND Q LEFT ONE BINARY POSITION AND SUBTRACT M FROM A; OTHERWISE, SHIFT A AND Q LEFT AND ADD M TO A. IF THE SIGN OF A IS 0, SET Q0 TO 1; OTHERWISE SET Q0 TO 0.
STEP 2:
The negative result is restored by adding, i.e., Ri ( R i - M ) +M ( 1) and is followed by a shift left one (i.e., multiplication by 2) and subtract: R i+1 2Ri-M (2) The two operations (1) and (2) are then merged into a single one:
R i+1
2 [( R i - M) + M] - M = 2 R i - M
CA - XII - ALU(3) - 6
M A
diviso r 0
Lef t -shift A, Q
A-M
A No
0?
Yes
Lef t -shif t A, Q
Q(0) A
0 A+ M
COUNT = n - 1? Yes
No COUNT COUNT+ 1
A No
CA - XII - ALU(3) - 7
1000 000 0000 000 Second cycle 0 0 00 000 Third cycle 0001 0 01 0 01 0 Quotient Restore remainder Fourth cycle First cycle
V x F0 = 1-y2 V x F0 x F1 = (1-y2) (1+y2) = 1-y4 Multiply top & bottom by (1+y), then (1+y2 ), ...
1 = 1 1 + y = (1 + y )( 1 + y 2 ) = y x 1 1 y2 1 y4
1 (1 + y )(1 + y 2 )(1 + y 4 )....(1 + y 2 ) = x 1 y 2i
i 1
Key idea: 0 Find a simple function (factor) so that by a repeated multiplication the value approaches 1
CA - XII - ALU(3) - 9
+ 1.23 * 102 9.999 999 x 1099 a. Sign is included as an extension of the mantissa. b. Exponent (1) Scale Factor (B) base or radix (2) Biasing. Exponent values are usually biased about some excess value. For example if we have an exponent field capable of having values 00 to 99 to represent plus and minus values we would assign exponents excess 50. The exponent -50 would be represented by 0, exponent 0 by 50, and exponent 49 by 99. 0 < EB < 99 Exponent Field -50 < E < 49 Exponent Represented The reason for using this technique is that the magnitudes of numbers may be compared without regard to whether the number is in floating-point format or not, i.e., magnitudes are compared in the same way as for integer arithmetic.
CA - XII - ALU(3) - 10
c) Hexadecimal (base 16) normalization example with excess 64-exponent (bias 64)
0 0000111 1....... +0.1...x27 Normalized version Normalization keeps mantissa at the value of 1 - 64<E< 63 2 <M<1 excess - 64 format E=E+ 64 0<E<127 1 0000011 -0.00000101...x163 1 0000010 -0.0101...x162
0 M63
E=255, M=0 c) Not-a-number E=255, M0 d) Normalized (-1)S * (1.M) 2E-127 0 < E < 255 e) Unnormalized (-1)S * (0.M) 2-126 E=1, M0 (This Number cannot be normalized because a shift to the left would cause an underflow.) Examples S Exponent 0 10000001 0 01111111 0 10000000
Mantissa implied 1 1.00...0 = 1.0 * 2129-127 = 4.0 1.10...0 = 1.5 * 2127-127 = 1.5 1.010...0 = 1.25 * 2128-127 = 2.5
CA - XII - ALU(3) - 13
Underflow occurs when a resulting biased exponent is less than zero (0). In such case the floating point word is set to all zeros. Overflow occurs when a resulting biased exponent is greater than the maximum value allowed for the exponent field. In both cases an error bit in a status word usually is set or an interrupt enabled so that a programm can determine what action to take following an underflow or overflow.
CA - XII - ALU(3) - 14
Normalization and changing the scale factor works like the pen and pencil method in scientific notation. Examples : 1.27 x 105 = .127 x 106 0.03 x 102 = .30 x 101 42.1 x 10-6 = .421 x 10-4 0.022 x 10-4 = .220 x 10-5 For binary shift a single shift by a sinlge position is required while for a hexadecimal shift a shift by four positions nescessary (implied radix 16)
CA - XII - ALU(3) - 15
110 110
110 110
CA - XII - ALU(3) - 16
ADD
CA - XII - ALU(3) - 17
CA - XII - ALU(3) - 18
DIV
1) SUBTRACT EXPONENTS 2) DIVIDE MANTISSAS & DETERMINE SIGN OF RESULT 3) NORMALIZE THE RESULTING VALUE IF NECESSARY 4) CHECK FOR OVERFLOW AND UNDERFLOW
OVERFLOW UNDERFLOW
Control bus
Control unit
Data bus
CA - XII - ALU(3) - 20
AC
MQ
DR
Exponent adder
Mantissa adder
CA - XII - ALU(3) - 21
CA - XII - ALU(3) - 22
n = | EA - EB |
ADD/SUB
ADD/ SUBTRACTION
sign
EA EB MPX E X
7-bit substractor Leading hex zeros detector
E-X R: S R , ER ,
CA - XII - ALU(3) - 23
MR
E1 - E2 E<0? No Yes
Right-shift DR E E+1
E>0?
No
Yes
Right-shift AC E E+1
Add-subtract mantissas
Yes
AC E
No
AC E AC - DR max ( E1, E2)
1. Comparison of the exponents by subtraction 1 2. Alignment of the mantissas by shifting 3. Addition or subtraction of the mantissas 4. Normalization of the result Tests are performed for overflow and for aXII - ALU(3)mantissa in the CA - zero - 24
Yes
E Yes
Right-shift AC
E+1
Exponent overflow ?
No
Yes
Stop
CA - XII - ALU(3) - 25
Adder 1
E5
M4 Shifter 1 M6
M5
M7 Adder 2 R Shifter 2 M3
CA - XII - ALU(3) - 26
1/4 Decoder
c1 c2
m Z
Z= c
1
X Y
+ OR
X Y
X Y
AND
EX - OR
NOT
CA - XII - ALU(3) - 27
Implementation of two conditional branch instructions SZA (skip on zero accumulator) and SNA (skip on nonzero accumulator)
Accumulator AC . . .
Count Enable
PC Program Counter
CA - XII - ALU(3) - 28
A>B A=B
A A Serial Shift B B B A AB AB B
. S R Q Q A>B A<B
. AB +AB 0
S R
CA - XII - ALU(3) - 29