You are on page 1of 11

Division Algorithms

Vikas Maheshkar
MNNIT, Allahabad
Rules for Division

Remainder = (Dividend – Quotient * Divisor)


Dividend=Quotient*Divisor + Remainder
(+7) / (+3): Q = 2; R = 1
(-7) / (+3): Q = -2; R = -1
(+7) / (-3): Q = -2; R = 1
(-7) / (-3): Q = 2; R = -1
2 Quotient
3 ) 7 Dividend
Divisor 6_
1
Remainder

2
Algorithms for Division

A logic circuit arrangement implements the restoring-division technique

3
Algorithms for Division

The restoring-division algorithm:


S1: DO n times
Shift A and Q left one binary position.
Subtract M from A, placing the answer back in A.
If the sign of A is 1, set q0 to 0 and add M back to A (restore A);
otherwise, set q0 to 1.

4
A restoring-division example

Initially 00000 1000


00011
Shift 00001 000
Subtract 111 01
First cycle
Set q0 11110
Restore 11
00001 0000
Shift 00010 000
Subtract 11101
Set q0 11111 Second cycle
Restore 11
00010 0000
Shift 00100 000
Subtract 11101
Third cycle
Set q0 00010 0001
Shift 00010 001
Subtract 11101
Fourth cycle
Set q0 11111
Restore 11
Quotient
00010 0010
remainder 5
Examples
A Q M = 0011

7/3: 0000 0111 Initial values


Shift
0000 1110 A=A-M 1
1101 1110 A=A+M
0000 1110 Shift
0001 1100 A=A-M 2
1110 1100 A=A+M
0001 1100
Shift
0011 1000 A=A-M
3
0000 1000 Q0 = 1
0000 1001
Shift
0001 0010 A=A-M 4
1110 0010 A=A+M
0001 0010
Algorithms for Division

The non-restoring division algorithm:


S1: 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.
S2: If the sign of A is 1, add M to A.

7
Signed Division
• Simplest solution
– Negate the quotient if the signs of divisor and
dividend disagree
– Remainder and dividend must have the same signs
• Remainder = (Dividend – Quotient * Divisor)
(+7) / (+3): Q = 2; R = 1
(-7) / (+3): Q = -2; R = -1
(+7) / (-3): Q = -2; R = 1
(-7) / (-3): Q = 2; R = -1
Signed Division Algorithm
START A, Q Dividend
M Divisor, Count n

Shift left: A, Q
S A31, Count Count - 1

No Yes
A A+M M31 = A31? A A-M

No S = A31? Yes

No A=0 and Yes Q0 1


Restore A
Q=0 ?

No Yes Quotient in Q
Count = END Remainder in A
0?
Examples (1/2)
A Q M = 0011 A Q M = 1101
0000 0111 Initial values 0000 0111 Initial values
Shift Shift
0000 1110 Subtract 1 0000 1110 Add 1
1101 Restore 1101 Restore
0000 1110 Shift 0000 1110 Shift
0001 1100 Subtract 2 0001 1100 Add 2
1110 Restore 1110 Restore
0001 1100 0001 1100
Shift Shift
0011 1000 Subtract 3 0011 1000 Add 3
0000 Q0 = 1 0000 Q0 = 1
0000 1001 0000 1001
Shift Shift
0001 0010 Subtract 4 0001 0010 Add 4
1110 Restore 1110 Restore
0001 0010 0001 0010
(7) / (3) (7) / (-3)
Examples (2/2)
A Q M = 0011 A Q M = 1101
1111 1001 Initial values 1111 1001 Initial values
Shift Shift
1111 0010 Add 1 1111 0010 Subtract 1
0010 Restore 0010 Restore
1111 0010 Shift 1111 0010 Shift
1110 0100 Add 2 1110 0100 Subtract 2
0001 Restore 0001 Restore
1110 0100 1110 0100
Shift Shift
1100 1000 Add 3 1100 1000 Subtract 3
1111 Q0 = 1 1111 Q0 = 1
1111 1001 1111 1001
Shift Shift
1111 0010 Add 4 1111 0010 Subtract 4
0010 Restore 0010 Restore
1111 0010 1111 0010
(-7) / (3) (-7) / (-3)

You might also like