Sie sind auf Seite 1von 13

Binary Division

Example (Paper and Pencil Method)


Divisor:
B=10001

1 1 0 1 0
0111000000
01110
011100
10001
010110
10001
001010
0010100
10001
000110

Quotient = Q
Dividend = A
5 bits of A < B, quotient has 5 bits
6 bits of A B
Shift right B and subtract; enter 1 in Q
6 bits of remainder B
Shift right B and subtract; enter 1 in Q
Remainder < B, enter 0 in Q; shift right B

Remainder B
Shift right B and subtract; enter 1 in Q
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
QS AS + BS
SC n 1

=0

AB
EA A + B
DVF 1

=0
A<B
EA A + B
DVF 0

AB

=1

Qn 1

A<B =0
EA A + B
SC SC 1
SC

END
(Divide Overflow)

=1
AA+ B + 1

EA A + B + 1

EA A + B + 1
=1

=0
END (Quotient in Q, Remainder in A)

Divisor B = 10001
B + 1 = 01111

Comment
Dividend:
Shl EAQ

Signed Magnitude Division


E
0

Add B + 1
E=1
Set Qn = 1
Shl EAQ
Add B + 1
E=1
Set Qn = 1
Shl EAQ
Add B + 1
E = 0, leave Qn = 0
Add B

1
1
0
1
1
0
0

SC

01110
11100
01111
01011
01011
10110
01111
00101
00101
01010
01111
11001
10001

00000
00000

00001
00010

00011
00110

00110

Divisor B = 10001
B + 1 = 01111

Comment
Restore remainder
Shl EAQ
Add B + 1
E=1
Set Qn = 1
Shl EAQ
Add B + 1
E = 0, leave Qn = 0

1
0

01010
10100
01111
00011
00011
00110
01111

1
1
0
0

Add B
Restore remainder
Neglect E
Remainder in A:
Quotient in Q

10101
10001
00110

SC
2

01100

01101
11010

11010
11010

00110
11010

2s Complement Division Algorithm

1.
2.
3.

Divisor M
Dividend A, Q
Shift A, Q left 1 bit position
If M and A have the same signs, perform A A M;
otherwise, A A + M
The preceding operation is successful if the sign of A is the
same before and after the operation
1.
2.

4.
5.

If the operation is successful or A = 0 and Q = 0, then set Q 0 1.


If the operation is unsuccessful and A 0, then set Q 0 0 and
restore the previous value of A.

Repeat steps 1 through 3 as many times as there are bit


positions in Q.
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) 2s complement division


Divisor M = 1101 = (-3)
M + 1 = 0011

Comment
Initial value
Shl AQ
Add
Restore
Shl AQ
Add

A
0000
0000
1101
1101
0000
0001
1101
1110

Q
0111
1110

SC
4

1110
1100

Sign of A and M are different so, A A + M


Sign of A before and after the operation are
different, so restore the value of A

Example: (7)/(-3) 2s complement division


Divisor M = 1101 = (-3)
M + 1 = 0011

Comment
Restore
Shl AQ
Add
Set Q0 = 1
Shl AQ
Add
Restore

SC

0001
0011
1101
0000
0000
0001
1101
1110
0001

1100
1000

1001
0010

0010

Signof
andand
Mand
are
different
so,
A Aare
+M
Signs
Sign
Sign
ofofA
divisor
AA
before
before
and
dividend
after
after
the
the
are
operation
operation
different
are
Answer:
different,
same, so
quotient
so
setrestore
Q0==1110
1the (-2),
valueremainder
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 =
q1q2q3qK/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
10 10 10 01
01
01
01 10
01 01
00 01
00 01 10
00 11 01
negative
00 01 10
00 01 10 01
00 01 10 01
Remainder = 00 00 0

= Q = 13
= A = 169
Subtract first test value 01
Answer positive; let q1 = 1
Bring down next pair
Subtract second test value 0q101
Answer positive; let q2 = 1
Bring down next pair
Subtract third test value 00q1q201
Answer negative; let q3 = 0
Restore partial remainder
Bring down next pair
Subtract fourth test value 000q1q2q301
Answer positive (zero); let q4 = 1

Problems
Perform signed-magnitude division and
twos complement division on 139 and -21
Perform signed-magnitude division and
twos 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