Unit II Students
Unit II Students
Unit II Students
Addition and subtraction of two numbers are basic operations at the machine-
instruction level in all computers. These operations, as well as other arithmetic and logic
operations, are implemented in the arithmetic and logic unit (ALU) of the processor. In this
unit, we present the logic circuits used to implement arithmetic operations. The time needed
to perform addition or subtraction affects the processor's performance. Multiply and divide
operations, require more complex circuitry than either addition or subtraction operations,
that also affects performance. Here we described the representation of signed binary
numbers, and showed that 2's-complement is the best representation from the standpoint of
performing addition and subtraction operations.
The truth table for the sum and carry-out functions for adding equally weighted
bits x; and yi in two numbers X and Y is given below.
At each stage of the addition process must accommodate a carry-in bit. We use ci to
represent the carry-in to stage i, which is the same as the carry-out from stage (i — 1).
23
The logic expression for si can be implemented with a 3-input XOR gate, used as part of the
A convenient symbol for the complete circuit for a single stage of addition, called
a Full adder (FA), is also shown in the figure.
24
Since the carries must propagate, or ripple, through this cascade, the
configuration is called a ripple-carry adder. The n-bit adder can be used to add 2's-
complement numbers X and Y, where the x„_1 and y„_1, bits are the sign bits.
The carry-in, co, into the least-significant-bit (LSB) position helps us to add 1 to a
number.
For example, the 2's-complement of a number can be formed by adding 1 to the
1's-complement of the number. The carry signals are also useful for interconnecting k
adders to form an adder capable of handling input numbers that are kn bits long, as shown
in Figure.
Subtraction operation X — Y :
Form the 2's-complement of Y and add it to X.
The following logic circuit can be used to perform either addition or subtraction
For addition:
This line is set to 0 for addition, then apply Y unchanged to one of the adder
25
For Subraction:
The Add/Sub control line is set to 1, so the Y number is 1 's-complemented by
reduce delay in adders is to use a logic gate network called a carry-lookahead network.
26
Gi is called the generate function for stage i. If the generate function for stage i
is equal to 1, then ci+1 = 1, independent of the input carry, ci. This occurs when both xi
and yi are 1.
Pi is called the propagate functions for stage i. The propagate function means
that an input carry will produce an output carry when either xi is 1 or yi is 1.
All Gi and Pi functions can be formed independently and in parallel in one logic
gate delay after the X and Y operands are applied to the inputs of an n-bit adder.
Propagate function can be implemented as Pi = xi yi.
Two 2-input XOR gates to realize the 3-input XOR function for si,
27
For a 4-bit adder the carries can be implemented independently as follows.
The complete 4 bit adder is shown in the diagram. The carries are produced in block labeled
Carry-lookahead logic.
28
2.3 Multiplication of Unsigned Numbers
The first operand is called the multiplicand and the second the multiplier. The final result
is called the product.
If we ignore the sign bits, the length of the multiplication of an n-bit multiplicand and an
m-bit multiplier is a product that is n+ m bits long.
29
The main component in each cell is a full adder, FA.
The AND gate in each cell determines whether a multiplicand bit, nth is added to
the incoming partial-product bit, based on the value of the multiplier bit, qi. Each row i,
where 0 ≤ i ≤ 3, adds the multiplicand (appropriately shifted) to the incoming partial
product, PPi, to generate the outgoing partial product, PP(i 1), if qi = 1. If qi = 0, PPi is
passed vertically downward unchanged. PP0 is all 0s, and PP4 is the desired product. The
multiplicand is shifted left one position per row by the diagonal signal path.
Registers A and Q are shift registers. Together, they hold partial product PPi
while multiplier bit qi generates the signal Add/Noadd. This signal causes the multiplexer
MUX to select 0 when qi = 0, or to select the multiplicand M when qi = 1, to be added to
PPi to generate PP(i + 1). The product is computed in n cycles.
30
The block diagram in Figure shows the hardware arrangement for sequential multiplication.
The partial product grows in length by one bit per cycle from the initial vector, PP0, of n
0’s in register A. The carry-out from the adder is stored in flip-flop C. shown at the left
endof register A.
At the start, the multiplier is loaded into register Q, the multiplicand into register M. and C
and A are cleared to 0. At the end of each cycle, C, A. and Q are shifted right one bit
position to allow for growth of the partial product as the multiplier is shifted out of
register Q.
Because of this shifting, multiplier bit 0 appears at the LSB position of Q to generate the
Add/No add signal at the correct time, starting with qo during the first cycle. qi during the
second cycle, and so on. After they are used, the multiplier bits are discarded by the right-
shift operation.
31
Note that the carry-out from the adder is the leftmost bit of PP(i + 1) and it must be held
in the C flip-flop to be shifted right with the contents of A and Q. After n cycles, the high-
order half of the product is held in register A and the low-order half is in register Q
The multiplication example as it would be performed by hardware arrangement
32
UNIT II COMPUTER ARITHMETIC
Addition and Subtraction of Signed Numbers - Design of Fast Adders - Multiplication of Unsigned Numbers
- Multiplication of Signed Numbers - Fast Multiplication - Integer Division - Floating-Point Numbers and
Operations
• In the above flowchart, initially, AC and Qn + 1 bits are set to 0, and the SC is a sequence counter that
represents the total bits set n, which is equal to the number of bits in the multiplier. There are BR that
represent the multiplicand bits, and QR represents the multiplier bits.
• After that, we encountered two bits of the multiplier as Qn and Qn + 1, where Qn represents the last bit
of QR, and Qn + 1 represents the incremented bit of Qn by 1. Suppose two bits of the multiplier is equal
to 10; it means that we have to subtract the multiplier from the partial product in the accumulator AC
and then perform the arithmetic shift operation (ashr).
• If the two of the multipliers equal to 01, it means we need to perform the addition of the multiplicand
to the partial product in accumulator AC and then perform the arithmetic shift operation (ashr),
including Qn + 1.
• The arithmetic shift operation is used in Booth's algorithm to shift AC and QR bits to the right by one
and remains the sign bit in AC unchanged. And the sequence counter is continuously decremented till
the computational loop is repeated, equal to the number of bits (n).
Working on the Booth Algorithm
1. Set the Multiplicand and Multiplier binary bits as M and Q, respectively.
2. Initially, we set the AC and Qn + 1 registers value to 0.
3. SC represents the number of Multiplier bits (Q), and it is a sequence counter that is continuously
decremented till equal to the number of bits (n) or reached to 0.
4. A Qn represents the last bit of the Q, and the Qn+1 shows the incremented bit of Qn by 1.
5. On each cycle of the booth algorithm, Qn and Qn + 1 bits will be checked on the following parameters
as follows:
i. When two bits Qn and Qn + 1 are 00 or 11, we simply perform the arithmetic shift right operation
(ashr) to the partial product AC. And the bits of Qn and Qn + 1 is incremented by 1 bit.
ii. If the bits of Qn and Qn + 1 is shows to 01, the multiplicand bits (M) will be added to the AC
(Accumulator register). After that, we perform the right shift operation to the AC and QR bits
by 1.
iii. If the bits of Qn and Qn + 1 is shows to 10, the multiplicand bits (M) will be subtracted from the
AC (Accumulator register). After that, we perform the right shift operation to the AC and QR
bits by 1.
6. The operation continuously works till we reached n - 1 bit in the booth algorithm.
7. Results of the Multiplication binary bits will be stored in the AC and QR registers.
• There are two methods used in Booth's Algorithm:
1. RSC (Right Shift Circular)
It shifts the right-most bit of the binary number, and then it is added to the beginning of the binary bits.
Example: Multiply the two numbers 7 and 3 by using the Booth's multiplication algorithm.
Ans. Here we have two numbers, 7 and 3.
• First of all, we need to convert 7 and 3 into binary numbers like 7 = (0111) and 3 = (0011).
• Now set 7 (in binary 0111) as multiplicand (M) and 3 (in binary 0011) as a multiplier (Q). And SC
(Sequence Count) represents the number of bits, and here we have 4 bits, so set the SC = 4. Also, it
shows the number of iteration cycles of the booth's algorithms and then cycles run SC = SC - 1 time.
Qn Qn + 1 M= (0111) AC Q Qn + 1 SC
M' + 1 = (1001) & Operation
1001
0101 0100
The numerical example of the Booth's Multiplication Algorithm is 7 x 3 = 21 and the binary representation of
21 is 10101. Here, we get the resultant in binary 00010101. Now we convert it into decimal, as
(000010101)10 = 2*4 + 2*3 + 2*2 + 2*1 + 2*0 => 21.
Example: Multiply the two numbers 23 and -9 by using the Booth's multiplication algorithm.
Here, M = 23 = (010111) and Q = -9 = (110111)
• Now set 23 (in binary 010111) as multiplicand (M) and -9 (in binary 110111) as a multiplier (Q). And
SC (Sequence Count) represents the number of bits, and here we have 6 bits, so set the SC = 6. Also,
it shows the number of iteration cycles of the booth's algorithms and then cycles run SC = SC - 1 time.
Qn Qn + 1 M=010111 AC Q Qn+1 SC
M' + 1 = 1 0 1 0 0 1
101001
010100
110011
Example:
A numerical example of booth’s algorithm is shown below for n = 4.
It shows the step-by-step multiplication of -5 and -7.
• Now set -5 (in 2’s 1011) as multiplicand (M) and -7 (in 2’s 1001) as a multiplier (Q). And SC (Sequence
Count) represents the number of bits, and here we have 4 bits, so set the SC = 4. Also, it shows the
number of iteration cycles of the booth's algorithms and then cycles run SC = SC - 1 time.
Qn Qn + 1 M= 1011 AC Q Qn+1 SC
M' + 1 = 0101
0101
1101
0100 0111
Advantages:
Faster than traditional multiplication: Booth’s algorithm is faster than traditional multiplication methods,
requiring fewer steps to produce the same result.
Efficient for signed numbers: The algorithm is designed specifically for multiplying signed binary numbers,
making it a more efficient method for multiplication of signed numbers than traditional methods.
Lower hardware requirement: The algorithm requires fewer hardware resources than traditional
multiplication methods, making it more suitable for applications with limited hardware resources.
Widely used in hardware: Booth’s algorithm is widely used in hardware implementations of multiplication
operations, including digital signal processors, microprocessors, and FPGAs.
Disadvantages:
Complex to understand: The algorithm is more complex to understand and implement than traditional
multiplication methods.
Limited applicability: The algorithm is only applicable for multiplication of signed binary numbers, and
cannot be used for multiplication of unsigned numbers or numbers in other formats without additional
modifications.
Higher latency: The algorithm requires multiple iterations to calculate the result of a single multiplication
operation, which increases the latency or delay in the calculation of the result.
Higher power consumption: The algorithm consumes more power compared to traditional multiplication
methods, especially for larger inputs.
Fast Multiplication
• Fast multiplication techniques like Bit Pair Recoding and Carry Save Adder (CSA) help in optimizing
binary multiplication by reducing the number of operations required and improving speed. Here's a
brief overview of each method:
1. Bit Pair Recoding
• Bit Pair Recoding optimizes binary multiplication by reducing the number of partial products
generated. Here's how it works:
Basic Idea:
• Instead of generating partial products for each bit in the multiplier, Bit Pair Recoding groups bits into
pairs to simplify the multiplication process.
Steps:
1. Group Bits in Pairs:
o Recoding groups of two bits are used to reduce the number of partial products. For example,
for a 4-bit multiplier, recoding might use pairs like (00, 01, 10, 11).
2. Use Recoding Rules:
o Each bit pair is recoded into a form that minimizes the number of required partial products. For
instance:
▪ 00 → 0
▪ 01 → 1
▪ 10 → -1 (with carry adjustment)
▪ 11 → 2 (can be handled with additional shifts)
3. Multiply and Shift:
o Apply the recoded values to the multiplicand, adjust for shifts, and sum the results.
Example: Multiply 6 by 5
Let’s multiply 6 and 5 using bit pair recoding.
011000
+ 000110
---------
011110
3. Convert Result Back to Decimal:
• Binary 0111102 = 3010.
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:
In this example, we will perform a division restoring algorithm.
1. Dividend = 11
2. Divisor = 3
N M A Q Operation
Now we will learn steps of the non-restoring division algorithm, which are 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, we will check the sign bit of A.
Step 3: If this bit of register A is 1, then shift the value of AQ through left, and perform A = A + M. If this bit
is 0, then shift the value of AQ into left and perform A = A - M. That means in case of 0, the 2's complement
of M is added into register A, and the result is stored into A.
Step 4: Now, we will check the sign bit of A again.
Step 5: If this bit of register A is 1, then Q[0] will become 0. If this bit is 0, then Q[0] will become 1. Here
Q[0] indicates the least significant bit of Q.
Step 6: After that, the value of N will be decremented. Here N is used as a counter.
Step 7: If the value of N = 0, then we will go to the next step. Otherwise, we have to again go to step 2.
Step 8: We will perform A = A + M if the sign bit of register A is 1.
Step 9: This is the last step. In this step, register A contains the remainder, and register Q contains the quotient.
For example:
In this example, we will perform a Non-Restoring Division algorithm with the help of an Unsigned integer.
1. Dividend = 11
2. Divisor = 3
3. -M = 11101
N M A Q Action
11.01
00.11
-----------
100.00
Multiplication:
• Multiply Significands: Perform binary multiplication on the significands.
• Add Exponents: Add the exponents of the two numbers and adjust for the bias.
• Normalize the Result: Adjust the result so that it fits the normalized format.
• Round the Result: Apply rounding rules.
Division:
• Divide Significands: Perform binary division on the significands.
• Subtract Exponents: Subtract the exponent of the divisor from the dividend and adjust for the bias.
• Normalize the Result: Adjust the result so that it fits the normalized format.
• Round the Result: Apply rounding rules.