You are on page 1of 12

Binary Division

Example (Paper and Pencil Method)


1 1 0 1 0 Quotient = Q
Divisor:
B=10001 0111000000 Dividend = A

01110 5 bits of A < B, quotient has 5 bits

011100 6 bits of A ≥ B

10001 Shift right B and subtract; enter 1 in Q

010110 6 bits of remainder ≥ B


10001 Shift right B and subtract; enter 1 in Q

001010 Remainder < B, enter 0 in Q; shift right B

0010100 Remainder ≥ B
10001 Shift right B and subtract; enter 1 in Q

000110 Remainder < B, enter 0 in Q

Final remainder: 000110


Signed magnitude Division Flow chart
Divide operation
Divide magnitudes
Dividend in AQ
Divisor in B
Shl EAQ
Q S ← AS + B S
SC ← n – 1 =0 E =1

EA ← A + B + 1 EA ← A + B + 1 A←A+B+1

=1 A≥B
=1 =0 E
E Qn ← 1
A≥B A<B A<B =0
EA ← A + B
EA ← A + B EA ← A + B
DVF ← 1 DVF ← 0
SC ← SC – 1

SC ≠0
END =0
(Divide Overflow) END (Quotient in Q, Remainder in A)
Signed – Magnitude Division
Divisor B = 10001
B + 1 = 01111
Comment E A Q SC
Dividend: 01110 00000 5
Shl EAQ 0 11100 00000
Add B + 1 01111
E=1 1 01011
Set Qn = 1 1 01011 00001 4
Shl EAQ 0 10110 00010
Add B + 1 01111
E=1 1 00101
Set Qn = 1 1 00101 00011 3
Shl EAQ 0 01010 00110
Add B + 1 01111
E = 0, leave Qn = 0 0 11001 00110
Add B 10001
Divisor B = 10001
B + 1 = 01111
Comment E A Q SC
Restore remainder 1 01010 2
Shl EAQ 0 10100 01100
Add B + 1 01111
E=1 1 00011
Set Qn = 1 1 00011 01101 1
Shl EAQ 0 00110 11010
Add B + 1 01111
E = 0, leave Qn = 0 0 10101 11010
Add B 10001
Restore remainder 1 00110 11010 0
Neglect E
Remainder in A: 00110
Quotient in Q 11010
2’s Complement Division Algorithm
• Divisor – M
• Dividend – A, Q
1. Shift A, Q left 1 bit position
2. If M and A have the same signs, perform A ← A – M;
otherwise, A ← A + M
3. The preceding operation is successful if the sign of A is the
same before and after the operation
1. If the operation is successful or A = 0 and Q = 0, then set Q 0 ← 1.
2. If the operation is unsuccessful and A ≠ 0, then set Q 0 ← 0 and
restore the previous value of A.
4. Repeat steps 1 through 3 as many times as there are bit
positions in Q.
5. The remainder is in A. If the signs of the divisor and
dividend were the same then the quotient is in Q; otherwise,
the correct quotient is the twos complement of Q.
Example: (7)/(-3) 2’s complement division
Divisor M = 1101 = (-3)
M + 1 = 0011
Comment A Q SC
Initial value 0000 0111 4
Shl AQ 0000 1110
Add 1101
1101
Restore 0000 1110 3
Shl AQ 0001 1100
Add 1101
1110

Sign
SignofofAAbefore
and Mand
are after the operation
different so, A ← Aare
+M
different, so restore the value of A
Example: (7)/(-3) 2’s complement division
Divisor M = 1101 = (-3)
M + 1 = 0011
Comment A Q SC
Restore 0001 1100 2
Shl AQ 0011 1000
Add 1101
0000
Set Q0 = 1 0000 1001 1
Shl AQ 0001 0010
Add 1101
1110
Restore 0001 0010 0
Signof
Signs
Sign
Sign ofofA
AAbefore
andand
divisor
beforeMand
are
and different
dividend
after
after the
the
areso, A ← Aare
operation
operation
different +M
are
Answer:
different,
same, so quotient
so
setrestore
Q0==1110
1the value
(-2), remainder
of A = 0001 (+1)
Square root algorithm
• Let A be the radicand (equivalent to dividend in division)
• Q – the square root
• R – the remainder
• Q2 + R = A or √A = Q and a remainder
• For K bits in A (K even), Q will have K/2 bits; Q =
q1q2q3…qK/2
• The first value is 01
• The second test value is 0q101
• The third test value is 00q1q201
• The fourth test value is 000q1q2q301 etc.
• Mark the bits of A in groups of two starting from left
Procedure for square root - Similar to division restoring method
q1 q2 q3 q4
1 1 0 1 = Q = 13

10 10 10 01 = A = 169
01 Subtract first test value 01
01 Answer positive; let q1 = 1
01 10 Bring down next pair
01 01 Subtract second test value 0q101
00 01 Answer positive; let q2 = 1
00 01 10 Bring down next pair
00 11 01 Subtract third test value 00q1q201
negative Answer negative; let q3 = 0
00 01 10 Restore partial remainder
00 01 10 01 Bring down next pair
00 01 10 01 Subtract fourth test value 000q1q2q301
Remainder = 00 00 0 Answer positive (zero); let q4 = 1
Problems
• Perform signed-magnitude division and
two’s complement division on 139 and -21
• Perform signed-magnitude division and
two’s complement division on 328 and 35
• Find the square root of 256
• Find the square root of 39
References
Text Book
• M. M. Mano, Computer System
Architecture, Prentice-Hall,2004
• W. Stallings, Computer organization and
architecture, Prentice-Hall,2000

You might also like