Lecture 5 - Division & Logic Operation
Lecture 5 - Division & Logic Operation
Lecture 5 - Division & Logic Operation
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
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
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 nonrestoringdivision example.
Nonrestoring
Division
Flow Chart
i.e 2A-
MIf A is (-)
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
Floating Point Division