Computer Arithmetic: Multiplication and Division
Arithmetic operations are at the core of all computing. While addition and subtraction are handled by simple adders, multiplication and division require more complex algorithms to handle sign bits and efficiency.
1. Binary Multiplication
The simplest form of multiplication is the 'Shift and Add' method. However, for signed numbers (2's complement), we use more sophisticated methods like Booth's Algorithm.
Booth's Algorithm
Booth's algorithm is a multiplication algorithm that multiplies two signed binary numbers in 2's complement notation. It speeds up the process by skipping sequences of 1s or 0s.
- **Look at current and previous bit ($Q_n, Q_{n+1}$):**
- **01:** Add Multiplicand to partial product.
- **10:** Subtract Multiplicand from partial product.
- **00 or 11:** Do nothing, just shift.
- **Arithmetic Right Shift:** Performed after every step.
2. Binary Division
Division is generally slower than multiplication. The two primary hardware algorithms are Restoring and Non-Restoring division.
- **Restoring Division:** If the result of a subtraction is negative, the partial remainder is 'restored' by adding the divisor back.
- **Non-Restoring Division:** Avoids the restoration step by performing an addition in the next step if the previous result was negative, making it slightly faster.
Comparison Table: Arithmetic Algorithms
| Operation | Algorithm | Key Characteristic |
|---|---|---|
| Multiplication | Shift and Add | Simplest, for unsigned numbers |
| Multiplication | Booth's Algorithm | Efficient for signed 2's complement |
| Division | Restoring | Adds back divisor if remainder is negative |
| Division | Non-Restoring | More efficient, no explicit restoration |
Hardware Implementation
Most modern CPUs contain a dedicated **Arithmetic Logic Unit (ALU)** with high-speed multipliers (like Wallace Tree multipliers) to perform these operations in just a few clock cycles.
Registers used in Multiplication:
A: Accumulator (Partial Product)
Q: Multiplier
M: Multiplicand
Common Mistakes to Avoid
- Forgetting to use 'Arithmetic' right shift in Booth's (which preserves the sign bit).
- Assuming division by zero is handled by the algorithm (it must be caught by hardware/OS exceptions).
- Confusing the Multiplier with the Multiplicand.
- Ignoring the overflow bit in fixed-point arithmetic.
Advanced Concepts
- Floating-point Multiplication/Division
- Wallace Tree Multipliers
- Carry-Save Adders (CSA)
- Newton-Raphson Division
- Array Multipliers
Practice Exercises
- Multiply (7) x (-3) using Booth's Algorithm step-by-step.
- What is the advantage of Non-Restoring division over Restoring division?
- Explain why we need an n+1 bit register for the Accumulator in Booth's algorithm.
- Perform a binary division of 1101 by 10 using the restoring method.
Conclusion
Efficient arithmetic algorithms are vital for performance in math-heavy applications like 3D graphics and AI. While addition is simple, the hardware's ability to quickly multiply and divide using Booth's and Non-Restoring methods defines the CPU's computational power.
Codecrown