Unit 2: Arithmetic and logic unit
Arithmetic and Logic Unit (ALU)
The Arithmetic and Logic Unit (ALU) is a core component of the CPU responsible for performing:
- Arithmetic operations (addition, subtraction, multiplication, division)
- Logic operations (AND, OR, NOT, XOR, comparisons)
The ALU works under the control of the Control Unit (CU) and uses data stored in registers.
Look-Ahead Carry Adder (Carry Look-Ahead Adder – CLA)
Problem with Ripple Carry Adder
In a Ripple Carry Adder, the carry must propagate through each full adder one by one, which causes delay.
Example:
-
For n-bit addition, delay ∝ n
To overcome this delay, Carry Look-Ahead Adders are used.
Concept of Carry Look-Ahead Adder
The Carry Look-Ahead Adder reduces delay by calculating carry signals in advance.
It uses two signals:
- Generate (G)
- Propagate (P)
For each bit position i:
-
Generate:
-
Propagate:
Carry equation:
Advantages of CLA
- Very fast addition
- Reduces carry propagation delay
- Used in high-performance processors
Disadvantages of CLA
- Complex hardware
- More logic gates required
- Cost increases with bit size
Multiplication in ALU
Multiplication is performed using shift and add operations.
Signed Operand Multiplication
Signed Numbers Representation
Signed numbers are usually represented using 2’s complement.
Rules:
- Positive number → same binary
- Negative number → 2’s complement
Signed Multiplication Process
Steps:
- Determine sign of result
- Multiply magnitudes
- Apply sign to result
However, direct multiplication is inefficient, so optimized algorithms are used.
Booth’s Algorithm
Booth’s Algorithm is an efficient algorithm for signed binary multiplication using 2’s complement representation.
It reduces the number of additions/subtractions.
Key Idea of Booth’s Algorithm
Booth’s algorithm examines:
- Current bit (Qn)
- Previous bit (Qn-1)
Booth’s Algorithm Rules
| Qn | Qn-1 | Operation |
|---|---|---|
| 0 | 0 | No operation |
| 0 | 1 | Add multiplicand |
| 1 | 0 | Subtract multiplicand |
| 1 | 1 | No operation |
After operation:
-
Arithmetic right shift is performed
Advantages
- Efficient for large numbers
- Handles positive and negative numbers
- Reduces number of operations
Disadvantages
- Algorithm complexity
- Difficult to understand for beginners
Array Multiplier
An Array Multiplier uses a regular array of adders and AND gates to perform multiplication.
Working Principle
Steps:
- Partial products are generated using AND gates
- Partial products are added using adders
- Final result is obtained
Features of Array Multiplier
- Parallel operation
- Fixed structure
- High speed
Advantages
- Fast multiplication
- Simple and regular layout
- Suitable for VLSI implementation
Disadvantages
- Large hardware requirement
- High power consumption
Division in ALU
Binary Division Concept
Binary division is similar to decimal long division.
Types:
- Restoring Division
- Non-restoring Division
Restoring Division Algorithm
Steps:
- Subtract divisor from partial remainder
- If result is negative, restore (add divisor back)
- Shift quotient and remainder
Non-Restoring Division
- Avoids restoration step
- Faster than restoring division
- Uses conditional add/subtract
Division Issues
- Slower than addition and multiplication
- Hardware complexity
- Overflow handling required
Logic Operations in ALU
The ALU performs basic logic operations bit-by-bit.
Basic Logic Operations
| Operation | Symbol | Description |
|---|---|---|
| AND | · | Output is 1 if both inputs are 1 |
| OR | + | Output is 1 if any input is 1 |
| NOT | ¬ | Inverts the bit |
| XOR | ⊕ | Output is 1 if inputs are different |
Logical Applications
- Masking bits
- Setting or clearing bits
- Data comparison
- Decision making in programs
Comparison Operations
ALU compares two values using:
- Less than
- Greater than
- Equal to
Flags affected:
- Zero flag
- Carry flag
- Sign flag
- Overflow flag
Summary Table
| Operation | Technique Used |
|---|---|
| Addition | Carry Look-Ahead Adder |
| Multiplication | Booth’s Algorithm, Array Multiplier |
| Division | Restoring / Non-Restoring |
| Logic | AND, OR, NOT, XOR |
Conclusion
The ALU is responsible for all arithmetic and logical computations in a processor.
Advanced techniques like Carry Look-Ahead Adders, Booth’s Algorithm, and Array Multipliers improve speed and efficiency.
Understanding these concepts is essential for mastering computer organization and architecture.
Floating Point Arithmetic, ALU Design, and IEEE Standard
A floating point number is used to represent real numbers (numbers with fractional parts), such as:
- 3.14
- −0.125
- 2.5 × 10³
Floating point representation allows a very large range of values using limited bits.
Floating Point Number Representation
A floating point number consists of three parts:
- Sign (S) – indicates positive or negative
- Exponent (E) – represents scale (power of base)
- Mantissa / Significand (M) – represents precision
General form:
Floating Point Arithmetic Operations
Floating Point Addition / Subtraction
Steps Involved:
- Compare Exponents - Make both exponents equal by shifting the mantissa of the smaller exponent.
- Align Mantissas - Right shift mantissa of the smaller exponent.
- Add/Subtract Mantissas - Perform arithmetic on aligned mantissas.
- Normalize the Result - Adjust mantissa so that it is in normalized form.
- Rounding - Apply rounding rules.
- Check for Overflow / Underflow - Handle exponent limits.
Floating Point Multiplication
Steps:
- Sign Calculation- Result sign = XOR of operand signs.
- Exponent Addition - Add exponents and subtract bias.
- Mantissa Multiplication - Multiply mantissas.
- Normalization- Adjust mantissa and exponent.
- Rounding - Apply rounding rules.
Floating Point Division
Steps:
- Sign Calculation - XOR of signs.
- Exponent Subtraction - Subtract divisor exponent from dividend exponent.
- Mantissa Division - Divide mantissas.
- Normalization & Rounding - Adjust result.
Problems in Floating Point Arithmetic
- Rounding errors
- Overflow
- Underflow
- Loss of precision
Arithmetic & Logic Unit (ALU) Design
Purpose of ALU Design
The design of ALU focuses on:
- Speed
- Accuracy
- Hardware efficiency
ALU design integrates:
- Arithmetic circuits
- Logic circuits
- Control logic
Basic Components of ALU Design
1. Arithmetic Unit- Adders (CLA, Ripple Carry)
- Subtractors
- Multipliers
- Dividers
2. Logic Unit
AND, OR, NOT, XOR gates
3. Shifter
- Logical shift
- Arithmetic shift
- Rotate operations
4. Control Unit
Selects operation using control signals
Block Diagram Description (Textual)
- Inputs from registers → ALU
- Control signals select operation
- Output stored back in registers
- Status flags updated
Status Flags in ALU
| Flag | Meaning |
|---|---|
| Zero (Z) | Result is zero |
| Carry (C) | Carry generated |
| Sign (S) | Result is negative |
| Overflow (V) | Overflow occurred |
Floating Point Unit (FPU)
- Specialized unit for floating point operations
- Integrated with ALU or separate
- Improves performance for real-number calculations
IEEE Standard for Floating Point Numbers (IEEE 754)
Need for IEEE Standard
- Uniform representation across systems
- Portability of programs
- Consistent arithmetic results
IEEE 754 Floating Point Formats
(a) Single Precision (32-bit)
| Field | Bits |
|---|---|
| Sign | 1 |
| Exponent | 8 |
| Mantissa | 23 |
Bias = 127
(b) Double Precision (64-bit)
| Field | Bits |
|---|---|
| Sign | 1 |
| Exponent | 11 |
| Mantissa | 52 |
Bias = 1023
Normalized Numbers
For normalized numbers:
- Leading bit of mantissa is 1 (implicit bit)
- Increases precision
Special Values in IEEE 754
| Value | Description |
|---|---|
| +0, −0 | Zero |
| +∞, −∞ | Overflow |
| NaN | Not a Number |
| Denormalized numbers | Very small values |
Rounding Modes
IEEE 754 supports:
- Round to nearest (default)
- Round toward zero
- Round toward +∞
- Round toward −∞
Advantages of IEEE Floating Point Standard
- Platform independence
- High precision
- Defined error handling
- Reliable scientific computation
Comparison: Fixed vs Floating Point
| Feature | Fixed Point | Floating Point |
|---|---|---|
| Range | Limited | Very large |
| Precision | Fixed | Variable |
| Hardware | Simple | Complex |
| Applications | Embedded | Scientific, AI |
Conclusion
Floating point arithmetic enables representation of real numbers with high precision and wide range.
The ALU design integrates arithmetic, logic, and control to ensure efficient computation.
The IEEE 754 standard ensures uniformity, accuracy, and portability in floating point operations.