COA Unit 2
COA Unit 2
Unit 2
Arithmetic And Logic Unit
Arithmetic And Logic Unit :- "ALU" stands for Arithmetic Logic Unit, a
fundamental component of a computer's central processing unit (CPU). It performs
arithmetic and logical operations, which are the basic building blocks of all
computations a computer carries out.
How it Works:
Inputs: The ALU receives input data in the form of binary numbers, along with
control signals that specify which operation to perform.
Operations: Using logic gates and circuitry, the ALU processes the inputs
based on the control signals.
Output: The result of the operation is sent to other components of the CPU or
stored in memory.
Half Adder :- A Half Adder is a combinational logic circuit that performs the
addition of two single-bit binary numbers, producing two outputs: Sum and Carry.
Key Features:
Inputs: Two binary digits, typically labeled as A and B.
Outputs:
1. Sum: The result of A+B without carry-over.
2. Carry: The carry-out bit, generated when A and B are both 1.
Logic Functions:
Sum: Sum=A⊕B (XOR gate)
Carry: Carry=A⋅B (AND gate)
Circuit Diagram:
1. Sum: Implemented using an XOR gate.
2. Carry: Implemented using an AND gate.
Full Adder :- Full Adder is the circuit that consists of two EX-OR gates, two AND
gates, and one OR gate. Full Adder is the adder that adds three inputs and produces
two outputs which consist of two EX-OR gates, two AND gates, and one OR gate. The
first two inputs are A and B and the third input is an input carry as C-IN. The output
carry is designated as C-OUT and the normal output is designated as S which is SUM.
Logic Functions:
Sum: Sum=A⊕B⊕Cin
(XOR gate used twice)
Carry-out: Cout=(A⋅B)+(B⋅Cin)+(A⋅Cin)
(Combination of AND and OR gates)
1. Array Multiplier
• Description: Uses a grid-like arrangement of AND gates and adders to
generate and sum partial products. It's based on the straightforward approach
of binary multiplication.
• Features:
• Simple to implement.
• High regularity in structure.
• Suitable for small-scale multiplications.
• Advantages: Easy to design and implement.
• Disadvantages: High area usage and significant propagation delay for large
operands.
• Applications: Basic processors and small embedded systems.
2. Booth Multiplier
• Description: Reduces the number of addition and subtraction operations by
encoding the multiplier bits, particularly useful for signed numbers in 2's
complement form.
• Features:
• Handles both positive and negative numbers efficiently.
• Works well with signed 2's complement representation.
• Advantages: Reduces the number of partial products, making it faster than
array multipliers.
• Disadvantages: Complex control logic.
• Applications: Signal processing and systems requiring efficient multiplication
of signed numbers.
4. Serial Multiplier
• Description: Multiplies numbers by processing one bit at a time, typically in
sequential clock cycles.
• Features:
• Requires less hardware.
• Slower than parallel multipliers.
• Advantages: Low area and power consumption.
• Disadvantages: Slow processing speed.
• Applications: Low-power embedded systems.
5. Parallel Multiplier
• Description: Operates on all bits simultaneously to produce results faster.
Includes array and Wallace tree multipliers as examples.
• Features:
• High-speed operation.
• Requires more hardware.
• Advantages: Fast and efficient for high-performance applications.
• Disadvantages: High power and area requirements.
• Applications: High-speed processors and real-time systems.
6. Carry-Save Multiplier
• Description: Uses carry-save adders to reduce the delay caused by carry
propagation in addition.
• Features:
• Optimized for high-speed operations.
• Advantages: Faster than conventional array multipliers.
• Disadvantages: Relatively complex structure.
• Applications: High-speed computation systems like GPUs and DSPs.
7. Logarithmic Multiplier
• Description: Multiplies numbers using logarithmic transformations, where
multiplication is reduced to addition of logarithms.
• Features:
• Ideal for approximate computing.
• Advantages: Energy-efficient for approximate operations.
• Disadvantages: Lower accuracy due to approximation.
• Applications: Image processing, machine learning, and neural networks.
8. Vedic Multiplier
• Description: Based on ancient Indian mathematics (Vedic sutras). Uses unique
methods to perform multiplication quickly and efficiently.
• Features:
• Optimized for small-sized multiplications.
• Advantages: Simple, scalable, and faster than traditional methods for small
operands.
• Disadvantages: Less efficient for large numbers without optimizations.
• Applications: Small embedded systems and arithmetic logic units.
• Generate (G): A carry is generated when both bits being added are 1.
Gi=Ai⋅Bi
• Propagate (P): A carry is propagated if at least one of the bits being added is 1.
Pi=Ai+Bi
• Carry Calculation: The carry for a particular bit position (Ci+1) is determined
using the generate and propagate signals: Ci+1=Gi+(Pi⋅Ci) This allows the carry
to be computed directly for any bit position without waiting for previous
carries.
The carry output Boolean function of each stage in a 4 stage carry look-ahead
adder can be expressed as
C1 = C0.P0+G0.
C2 = C1.P1+G1 = ( C0.P0+G0).P1+G1.
C3 = C2.P2+G2 = (C1.P1+G1).P2+G2.
* Multiplicand
* Multiplier
1. Registers: Two Registers B and Q are used to store multiplicand and multiplier
respectively. Register A is used to store partial product during multiplication.
Sequence Counter register (SC) is used to store number of bits in the multiplier.
2. Flip Flop: To store sign bit of registers we require three flip flops (A sign, B sign
and Q sign). Flip flop E is used to store carry bit generated during partial product
addition.
• If Qn=1:
• Add the Multiplicand (B) to the A register.
• Store the result in A, with any carry bit saved in the E flip-flop.
• If Qn=0:
• Skip the addition.
3. Right Shift Operation:
• Shift the contents of E,A,Q (combined as one logical unit) to the right by
one position:
• The value in E moves to the most significant bit (MSB) of A.
• The LSB of A moves to the MSB of Q.
4. Decrement the Sequence Counter (SC):
• If SC=0, stop the process. The final product is stored in A (higher bits)
and Q (lower bits).
• Otherwise, repeat from Step 2.
6. Final Adjustment:
• If As=1 (negative result), take the two's complement of the result to get
the correct signed product.
Booth’s Algorithm :-
Booth's algorithm is a method used to multiply binary numbers in signed 2's
complement format, designed to make the process more efficient by reducing the
number of additions or subtractions required. It works by taking advantage of
patterns in the multiplier, such as strings of consecutive 0's or 1's, to minimize
operations. Here's a breakdown of the approach in simpler terms:
2. Handling consecutive 1's: If there's a string of 1's in the multiplier, you can
treat the sequence as a larger number and perform fewer operations,
essentially reducing the number of steps needed.
• If you encounter a 1 after a 0 in the multiplier (i.e., the first "1" in a series
of 1's), subtract the multiplicand from the current result.
• If you encounter a 0 after a 1 (the first "0" in a series of 0's), add the
multiplicand to the current result.
• If the current multiplier bit is the same as the previous bit (i.e., no
change), then do nothing to the result.
The main idea is to look at the bits of the multiplier and decide whether to add,
subtract, or leave the partial product unchanged based on these patterns, and then
shift the result as needed. This helps speed up the multiplication process compared
to traditional methods.
double inspection of the multiplier. The flowchart for the booth algorithm is
shown below.
Array Multiplier :-
An array multiplier is a type of digital circuit used to perform binary multiplication. It
is a straightforward implementation of the multiplication process, and it uses an
array of AND gates and adders to compute the product of two binary numbers.
1. Partial Product Generation: For each bit of the multiplier, you generate a
partial product by ANDing it with each bit of the multiplicand. This step
produces multiple rows of partial products, depending on the number of bits in
the two numbers being multiplied.
2. Addition of Partial Products: Once the partial products are generated, they
need to be added together to get the final result. This addition is done using
binary adders, such as full adders or half adders.
3. Final Sum: After the partial products are added, the final sum gives the result
of the multiplication.
• A=a3a2a1a0 (multiplicand)
• B=b3b2b1b0 (multiplier)
Step 3: Result:
The result of the addition of the partial products gives the final product of the
multiplication.
Advantages:
• Simple to implement.
• Well-suited for small systems.
Disadvantages:
• Requires restoring the original remainder when subtraction results in a
negative value, which adds an extra step.
Steps:
1. Initialize: Set the remainder to 0 and the quotient to 0.
2. Shift Left: Shift the remainder and the next bit of the dividend into the
remainder register.
3. Condition Check:
• If the remainder is non-negative, subtract the divisor.
• If the remainder is negative, add the divisor.
4. Set Quotient Bit:
• If subtraction was performed, set the quotient bit to 1.
• If addition was performed, set the quotient bit to 0.
5. Repeat: Continue for the number of bits in the dividend.
6. Final Adjustment:
• If the remainder is negative after all iterations, add the divisor once to
get the final remainder.
7. Output: The quotient and adjusted remainder.
Advantages:
• Faster than the restoring division algorithm since it skips the restoring step.
• Efficient in hardware implementations.
Disadvantages:
• Slightly more complex control logic than restoring division.
Steps:
1. Convert the dividend and divisor to positive if they are negative, keeping track
of their signs.
2. Perform binary division using restoring or non-restoring methods.
3. Adjust the quotient's sign based on the original signs of the dividend and
divisor.
4. Adjust the remainder's sign to match the dividend's sign.
Advantages:
• Handles signed operations efficiently.
Disadvantages:
• Requires additional checks and adjustments for signed values.
Steps:
1. Divide the leading digits of the dividend by the divisor to estimate the next
digit of the quotient.
2. Multiply the estimated quotient digit by the divisor and subtract it from the
current dividend portion.
3. Bring down the next digit from the dividend and repeat.
4. Continue until all digits of the dividend are processed.
Advantages:
• Suitable for operations where precision matters, such as floating-point division.
Disadvantages:
• Iterative and time-consuming.
5. Newton-Raphson Division (Iterative Approximation)
This algorithm approximates division using reciprocal values. It is widely used in
floating-point arithmetic.
Concept:
• Division is represented as Q=D×R, where Q is the quotient, D is the divisor, and
R is the reciprocal of D.
• The reciprocal R is calculated iteratively using Newton-Raphson iteration: Rn+1
=Rn(2−D×Rn)
• Once R converges, the quotient is computed as Q=Dividend×R.
Advantages:
• Very fast for high-precision division.
• Suitable for floating-point units (FPUs).
Disadvantages:
• Requires additional hardware or software for iterative approximation.
Concept:
• The quotient is calculated using a radix-based representation (typically radix-2
or radix-4).
• The process involves generating partial remainders and using them to
determine the next quotient digit from a precomputed table.
Advantages:
• Reduces the number of iterations compared to other methods.
• Efficient for hardware implementation in processors.
Disadvantages:
• Requires additional logic for table lookup.
Comparison of Division Algorithms
Complexit
Algorithm Speed Applications
y
Basic hardware and
Restoring Division Slow Simple
educational tools
Non-Restoring Faster than
Moderate Hardware implementation
Division Restoring
Signed Division Moderate Moderate Processors and ALUs
Digit-by-Digit Division Slow Simple Software-based division
Newton-Raphson
Very Fast Complex Floating-point arithmetic
Division
SRT Division Fast Moderate High-speed CPUs and FPUs
In this section, we are going to perform restoring algorithm with the help of an unsigned
integer. We are using restoring term because we know that the value of register A will be
restored after each iteration. We will also try to solve this problem using the flow chart and
apply bit operations.
Here, register Q is used to contain the quotient, and register A is used to contain the
remainder. Here, the divisor will be loaded into the register M, and n-bit divided will be
loaded into the register Q. 0 is the starting value of a register. The values of these types of
registers are restored at the time of iteration. That's why it is known as restoring.
Now we will learn some steps of restoring division algorithm, which is described as follows:
Step 1: In this step, the corresponding value will be initialized to the registers, i.e., register
A will contain value 0, register M will contain Divisor, register Q will contain Dividend, and N
is used to specify the number of bits in dividend.
Step 2: In this step, register A and register Q will be treated as a single unit, and the value
of both the registers will be shifted left.
Step 3: After that, the value of register M will be subtracted from register A. The result of
subtraction will be stored in register A.
Step 4: Now, check the most significant bit of register A. If this bit of register A is 0, then
the least significant bit of register Q will be set with a value 1. If the most significant bit of A
is 1, then the least significant bit of register Q will be set to with value 0, and restore the
value of A that means it will restore the value of register A before subtraction with M.
Step 5: After that, the value of N will be decremented. Here n is used as a counter.
Step 6: Now, if the value of N is 0, we will break the loop. Otherwise, we have to again go to
step 2.
Step 7: This is the last step. In this step, the quotient is contained in the register Q, and the
remainder is contained in register A.
For example:
1. Dividend = 11
2. Divisor = 3
N M A Q Operation
Floating-Point Representation
Floating-point numbers are generally represented in the IEEE 754 standard, which
consists of three main components:
1. Sign (S):
• A single bit that determines the sign of the number.
• 0 for positive numbers and 1 for negative numbers.
2. Exponent (E):
• Encodes the magnitude or scale of the number, often stored in a biased
format to allow both positive and negative exponents.
3. Mantissa (M) (or significand):
• Represents the significant digits of the number. In normalized form, the
leading digit is implicitly 1 (not stored explicitly in binary representation).
Value=(−1)S×(1.M)×2E−Bias
• Bias is a constant used to interpret the exponent (e.g., 127 for single-precision,
1023 for double-precision).
2. Multiplication
3. Division
FLOATING POINT ADDITION :-
To understand floating point addition, first we see addition of real numbers in
decimal as same logic is applied in both cases.
0. 00010010000000000000000
+ 1. 00111000000000000000000
————————————————-
1. 01001010000000000000000
In final answer, we take exponent of bigger number
Sign bit = 0
Exponent of bigger number = 10000010
Mantissa = 01001010000000000000000
32 bit representation of answer = x + y = 0 10000010 01001010000000000000000
0. 00010010000000000000000
– 1. 00111000000000000000000
————————————————
1. 00100110000000000000000
Sign bit of bigger number = 0
So, finally the answer = x – y = 0 10000010 00100110000000000000000
In this continuation of the previous set, we will cover some more concepts and
operations involved in computer arithmetic:
1.Signed vs. unsigned numbers: In computer arithmetic, numbers can be either
signed numbers can represent both positive and negative values. Signed numbers
2.Shift operations: Shift operations are used to move the bits of a number left or
right. A left shift multiplies the number by 2 raised to the power of the number of
shifted bits, while a right shift divides the number by 2 raised to the power of the
3.Logical vs. arithmetic shifts: Shift operations can be either logical or arithmetic.
Logical shifts insert zeros into the vacant bit positions, while arithmetic shifts
4.Carry and borrow: In addition and subtraction operations, carry and borrow
refer to the bit that is carried over or borrowed from the next digit position when
Overall, computer arithmetic is a complex and important field that underlies many
aspects of modern computing. It involves a wide range of concepts and operations,
from basic addition and subtraction to advanced algorithms for multiplication and
division.
Floating-Point Multiplication:-
Floating-point multiplication involves multiplying two numbers represented in
floating-point format. It operates on the mantissa, exponent, and sign of the
numbers separately, following specific steps to ensure proper computation while
adhering to the IEEE 754 standard.
• Sign = 0(positive).
2. Add Exponents:
• 129+125−127=127.
3. Multiply Mantissas:
• Mantissas: 1.1011×1.0=1.1011.
• Result = 1.1011.
4. Normalize the Result:
Floating-Point Division:-
Floating-point division is the process of dividing two floating-point numbers,
following IEEE 754 standard representation. It operates on the sign, exponent, and
mantissa separately to calculate the result. Careful handling of normalization,
rounding, and special cases is required.
• Subtract the exponent of the divisor from the exponent of the dividend
and adjust for bias: Eresult=Edividend−Edivisor+Bias
• Bias values:
• 127 for single-precision.
• 1023 for double-precision.
3. Divide the Mantissas:
• Divide the mantissas (significands) of the dividend and divisor.
• The result may fall out of the normalized range (1.0≤M<2.0).
4. Normalize the Result:
• If the result of the mantissa division is not normalized, shift the mantissa
and adjust the exponent accordingly.
5. Round the Result:
• Apply rounding to fit the mantissa into the available precision bits.
6. Handle Special Cases:
• Zero:
• Dividing zero by a non-zero number results in zero.
• Dividing a non-zero number by zero results in infinity.
• Infinity:
• Dividing infinity by a finite number results in infinity.
• Dividing a finite number by infinity results in zero.
• NaN:
• Division involving NaN produces NaN.
7. Format the Result:
• Combine the calculated sign, exponent, and mantissa into the final
floating-point representation.
Example: Divide 6.75 by 0.25
Step 1: Represent the Numbers in IEEE 754 Format
• 6.75 (Single-Precision):
• Sign = 0(positive).
2. Subtract Exponents:
• 129−125+127=131.
3. Divide Mantissas:
• Mantissas: 1.1011÷1.0=1.1011.
• Result = 1.1011.
4. Normalize the Result:
Types of Microoperations
1. Data Transfer Microoperations
These operations move data from one location to another, such as between registers
or between registers and memory.
2. Arithmetic Microoperations
These perform basic arithmetic calculations like addition, subtraction, increment, and
decrement.
• Examples:
• Addition: R1←R2+R3 Add the contents of R2 and R3, store the result in
R1.
• Subtraction: R1←R2−R3 Subtract R3 from R2, store the result in R1.
• Increment: R1←R1+1 Increase the content of R1 by 1.
• Decrement: R1←R1−1 Decrease the content of R1 by 1.
3. Logical Microoperations
These perform bitwise logical operations on the binary data of registers.
• Operations:
• AND: R1←R2ANDR3 Perform bitwise AND on R2 and R3, store the result
in R1.
• OR: R1←R2ORR3 Perform bitwise OR on R2 and R3, store the result in R1.
• XOR: R1←R2XORR3 Perform bitwise XOR on R2 and R3, store the result in
R1.
• NOT: R1←NOTR2 Perform bitwise negation (complement) on R2, store
the result in R1.
4. Shift Microoperations
These operations shift the binary content of a register to the left or right. Shifting can
be logical, arithmetic, or circular.
• Types:
1. Logical Shift:
• Bits that are shifted out from one end are reintroduced at the
opposite end.
• Example:
• Circular left shift: Rotate bits left.
• Circular right shift: Rotate bits right.
Detailed Examples
1. Data Transfer Microoperation:
• Instruction: R1←R2.
• Meaning: The content of register R2 is copied into R1. The original value
in R2 remains unchanged.
2. Arithmetic Microoperation:
• Instruction: R1←R2+R3.
• Meaning: Add the contents of R2 and R3, and store the result in R1.
3. Logical Microoperation:
• Instruction: R1←R2XORR3.
• Meaning: Perform bitwise XOR on the binary contents of R2 and R3, and
store the result in R1.
4. Shift Microoperation:
• Instruction: R1←shlR1.
• Meaning: Perform a logical left shift on R1, moving all bits one position
to the left, and filling the rightmost position with 0.
ALU derives its name because it performs arithmetic and logical operations. A simple
multiplication and division are designed around the circuits developed for these
operations while implementing the desired algorithm. More complex ALUs are
designed for executing Floating point, Decimal operations and other complex
numerical operations. These are called Coprocessors and work in tandem with the
main processor.
The design specifications of ALU are derived from the Instruction Set Architecture.
The ALU must have the capability to execute the instructions of ISA. An instruction
LOAD instruction brings data from memory location and writes onto a GPR. The
discuss Datapath more in details in the next chapter on Control Unit Design. The
11.1. The ALU has two inputs A and B. These inputs are fed to AND gate, OR Gate and
Full ADDER. The Full Adder also has CARRY IN as an input. The combinational logic
output of A and B is statically available at the output of AND, OR and Full Adder. The
desired output is chosen by the Select function, which in turn is decoded from the
instruction under execution. Multiplexer passes one of the inputs as output based on
this select function. Select Function essentially reflects the operation to be carried out
on the operands A and B. Thus A and B, A or B and A+B functions are supported by
this ALU. When ALU is to be extended for more bits the logic is duplicated for as
many bits and necessary cascading is done. The AND and OR logic are part of the
The simplest ALU has more functions that are essential to support the ISA of the CPU.
Therefore the ALU combines the functions of 2's complement, Adder, Subtractor, as
part of the arithmetic unit. The logical unit would generate logical functions of the
form f(x,y) like AND, OR, NOT, XOR etc. Such a combination supplements most of a
CPU's fixed point data processing instructions.