Implementation of Restoring Division Algorithm for unsigned integer
In the previous article, we have already discussed the Restoring Division Algorithm. In this article, we will discuss the implementation of this algorithm.
Restoring Division Algorithm is used to divide two unsigned integers. This algorithm is used in Computer Organization and Architecture. This algorithm is called restoring because it restores the value of Accumulator(A) after each or some iterations. There is one more type i.e. Non-Restoring Division Algorithm in which value of A is not restored. Let the dividend Q = 0110 and the divisor M = 0100. The following table demonstrates the step by step solution for the given values:
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
|Step 1: Left-Shift||0000||110_|
|A – M||1100||Unsuccessful(-ve)|
|Step 2: Left-Shift||0001||100_|
|A – M||1101||Unsuccessful(-ve)|
|Step 3: Left-Shift||0011||000_|
|A – M||1111||Unsuccessful(-ve)|
|Step 4: Left-Shift||0110||000_|
|A – M||0010||0001||Successful(+ve)|
Approach: From the above solution, the idea is to observe that the number of steps required to compute the required quotient and remainder is equal to the number of bits in the dividend. Initially, let the dividend be Q and the divisor be M and the accumulator A = 0. Therefore:
- At each step, left shift the dividend by 1 position.
- Subtract the divisor from A(A – M).
- If the result is positive, then the step is said to be successful. In this case, the quotient bit will be “1” and the restoration is not required.
- If the result is negative, then the step is said to be unsuccessful. In this case, the quotient bit will be “0” and restoration is required.
- Repeat the above steps for all the bits of the dividend.
Note: Here, restoration is performed by adding back the divisor to A.
Initial Values: A: 0000 Q: 0110 M: 0100 step: 1 Left Shift and Subtract: A: 1100 A: 1100 Q: 110_ -Unsuccessful A: 0000 Q: 1100 -Restoration step: 2 Left Shift and Subtract: A: 1101 A: 1101 Q: 100_ -Unsuccessful A: 0001 Q: 1000 -Restoration step: 3 Left Shift and Subtract: A: 1111 A: 1111 Q: 000_ -Unsuccessful A: 0011 Q: 0000 -Restoration step: 4 Left Shift and Subtract: A: 0010 A: 0010 Q: 000_ Successful A: 0010 Q: 0001 -No Restoration Quotient(Q): 0001 Remainder(A): 0010