Lecture 5 - Division & Logic Operation

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

UNIT – 2 : LECTURE-5

Division & Logic


Operation
Binary Division
Hardware Implementation
Eg of normal division :

100010010/1101
10101

1101 |
100010010
-1101
10000
-1101

1110
- 1101
1
1 0 1 0
1010 | 110 1 0 0 1
- 110 1

011 0
- 101 0
1

1
+

1
Restoring Division
Shift A and Q left one binary position
Subtract M from A, and place 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
Repeat these steps n times
Positive divisor - - -  Reg.

M Positive dividend - 

Reg Q Reg A--0

After division is

complete Quotient
----- Q
Remainder ----- A
A 0 bit is added at the left end of both A and M to serve as a sign
bit for subtraction.
Algorithm :
Do n times ( n-- no. of bits in Q)
1. Shift A and Q left one binary position.
2. Subtract M from A, placing the answer back in A (A=A-M)
3. If the sign of A is 1 set qo to 0 and add M back to A (restore A ) , otherwise set q0 to
1.
Restoring Division
Flow Chart
Examples Initially 0 0 0 0 0

Shift
0 0 0 1 1
0000 1
100 0

00 0
Subtract 1 1 1 0 1 First cycle
Set q0 1 1 1 1 0
Restore 11
0000 1 000 0
10 Shift 0001 0 00 0
1 1 1000 Subtract 1 1 1 0 1
11 Second cycle
Set q0 1111 1
Restore 11
10 0001 0 000 0
Shift 0010 0 00 0
Subtract 1 1 1 0 1
0000 1 Third cycle
Set q0
000 1
Shift
Subtract 101010011 0 00 1
Set q0 1 1 1 1 1 Fourth cycle
Restore 1 1
0 0 0 1 0 001 0

Remainder Quotient

Figure 6.22. A restoring­division example.


1. 9 / 5
1001
101 Q
M 010 A 0000
1 1. Sh 1001 001
Sub (A=A-M) 0001
1100 001
+0101 0
0001

2. Sh 010
0010
Sub (A=A-M) 1101 010
+010 0
1
0010
M
A Q
010
1
3. Sh 0100 100
Sub (A=A-M) 1111 100
+0101 0

0100
4. Sh 1001 000
Sub (A=A-M) 0100 000
1
Remainder Quotient
2. 12 / 10
1100 1010
M A Q
01010 00000 1100
1. Sh 00001 100
Sub (A=A-M) 10111 100
Restore 0
00001
000
2. Sh 00011 000
Sub (A=A-M) 11001 0
Restore
00011
M
A Q
0101
0
3. Sh 0011 00
0
Sub (A=A-M) 11100 0
0000
Restore 00110

4. Sh 01100 000
Sub (A=A-M) 00010 0001

Remainder Quotient
3. 4 / 5
100 101
M A Q
0101 0000 100
1. Sh 0001 00
Sub (A=A-M) 1100 00
Restore 0
0001
00
2. Sh 0010 00
Sub (A=A-M) 1101 0
Restore 0010
M
A Q
010
1
3. Sh 0100 00
Sub (A=A-M) 1111 00
Restore 0100 0
Remainder Quotient
Nonrestoring Division

Avoid the need for restoring A after


an unsuccessful subtraction.
Any idea?
Step 1: (Repeat n times)
 If the sign of A is 0, shift A and Q left one bit position and
subtract M from A; otherwise, shift A and Q left and add M
to A.
 Now, if the sign of A is 0, set q0 to 1; otherwise, set q0 to 0.
Step2: If the sign of A is 1, add M to A
Examples Initially 0 0 0 0 0
0 0 0 1 1
1 0 0 0

Shift 0 0 0 0 1 0 0 0 First cycle


Subtract 1 1 1 0 1
Set q 0 1 1 1 1 0 0 0 0 0

Shift 1 1 1 0 0 0 0 0
Add 0 0 0 1 1 Second cycle

Set q0 1 1 1 1 1 0 0 0 0

Shift 1 1 1 1 0 0 0 0
1 1 1 1 1 Add 0 0 0 1 1 Third cycle
Restore
0 0 0 1 1 Set q0 0 0 0 0 1 0 0 0 1
Add 0 0 0 1 0 remainder

Remaind Shift 0 0 0 1 0 0 0 1
er Subtract 1 1 1 0 1 Fourth cycle
Set q0 1 1 1 1 1 0 0 1 0

Quotient
A nonrestoring­division example.
Nonrestoring
Division
Flow Chart

i.e 2A-
 MIf A is (-)

1. Restore A---- A+M


2. Left Shift 2(A+M)
3.Subtract M from A
2(A+M)-M= 2A+M
Algorithm :
4. Do n times (n---no.
of bits in Q)
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 else set q0 to 0.
2. After n iterations , if the sign of A is 1, add M to A
 Eg :
8/3 M A Q
011 00 100
1. Sh001 0 00 0
Sub 0 000
00
110 000
2. Sh 00
000
100
1
00
Add 111
1
0010
3. Sh 110
111
Add 001
+01 Quotient
4. Sh 010
1010---Remainder
Sub

Eg :
15/3
M A Q
011 000 1111
1. Sh001 111
Sub 110 1110
2. Sh 101 110
Add 000 1101

3. Sh 001 101
Sub 110 1010

4. Sh 101 010
Add 000 0101
Remainder Quotient
For division : X=Xm x 2^Xe

Y=Ym x 2^Ye
Z=(Xm/Ym) x 2^(Xe-Ye)


Note when the divisor exponent (Xe+127) is
subtracted from dividend exponent (Ye+127), it
removes the bias which must be added back in
i.e ((Xe+127) -(Ye+127)) = Xe-Ye

Hence correction-- (Xe-Ye) +127

Case 1 : Assume Xe= 120 , Ye= -


2 Xe’= 147 Ye’= +125
Xe’-Ye’=272


Floating Point Division

You might also like