Unit 6 Fixed Point Computer Arithmetic: Addition and Subtraction
Unit 6 Fixed Point Computer Arithmetic: Addition and Subtraction
Arithmetic instructions manipulate data to produce solution for computational problems. The 4 basic
arithmetic operations are addition, subtraction, multiplication and division. From these 4, it is possible
to formulate other scientific problems by means of numerical analysis methods. Here, we’ll discuss
these 4 operations only on fixed-point binary data (there are other types too, viz. floating point binary
data, binary-coded decimal data) and hence the unit named.
Hardware Implementation
To implement the two arithmetic operations with hardware, we have to store numbers into two register
A and B. let As and Bs be two flip-flops that holds corresponding signs. The result is transferred to A and
As. A and As together form a accumulator.
We need:
Consists of two resisters A and B
and sign flip-flops As and Bs.
A magnitude comparator: to
check if A>B, A<B or A=B.
A parallel adder: to perform A+B
Two parallel subtractors: for A-B
and B-A
The sign relationships are
determined from an exclusive-
OR gate with As and Bs as inputs.
Fig: hardware for signed-magnitude addition and subtraction
Page 1
Block Diagram Description: hardware above consists of registers A and B and sign flip-flops As and Bs.
subtraction is done by adding A to the 2’s complement of B. Output carry is transferred to flip-flop E,
where it can be checked to determine the relative magnitude of two numbers. Add-overflow flip-flop
AVF holds overflow bit when A and B are added. Addition of A and B is done through the parallel adder.
The S output of adder is applied to A again. The complementer provides an output of B or B’ depending
on mode input M. Recalling unit 2, when M = 0, the output of B is transferred to the adder, the input
carry is 0 and thus output of adder is A+B. when M=1, 1’s complement of B is applied to the adder, input
carry is 1 and output is S = A+B’+1 (i.e. A-B).
Hardware Algorithm
The flowchart for the H/W algorithm is given below:
Page 2
Register configuration is same as signed-
magnitude representation except sign bits are not
separated. The leftmost bits in AC and BR represent
sign bits.
Example: 33 + (-35)
AC = 33 = 00100001
BR = -35 = 2’s complement of 35 = 11011101
AC + BR = 11111110 = -2 which is the result
Multiplication
Signed-magnitude representation
For this representation, multiplication is done by a process of successive shift and adds operations. As an
example:
Page 3
Hardware implementation for signed-magnitude data
It needs same hardware as that of addition and subtraction of signed-magnitude. In addition it needs
two more registers Q and SC.
Hardware Algorithm
Flowchart below shows a hardware multiply algorithm.
Page 4
Signed 2’s complement representation
Inspiration: String of 1’s in the multiplier from bit weight 2k to weight 2m can be treated as 2k+1-2m. As an
example, binary number 001110 (+14) has string of 1’s from 23 to 21 (k=3, m=1). So, this number can be
represented as 2k+1 - 2m = 24 - 21 = 16 – 2 = 14 (case is similar for -14 (110010) = -24+22-21). Thus, M * 14 =
M * 24 – M * 21; product can be obtained by shifting multiplicand M four times left and subtracted M
shifted left once.
As in other multiplication schemes, Booth algorithm also requires examination of multiplier bits and
shifting of the partial product. Prior to shifting multiplicand may be:
Subtracted <-- upon the encountering first least significant 1 in the string of 1’s in the multiplier.
Added <-- upon encountering first 0 (left of it must be 1) in string of 0’s in the multiplier.
Unchanged <-- when multiplier bit (Qn) is identical to previous multiplier bit (Qn+1)
Page 5
Array Multiplier
Checking the bits of the multiplier one at a time and forming partial products is a sequential operation
requiring sequence of add and shift microoperations. The multiplication of two binary numbers can be
done with one microoperation by using combinational circuit that forms product bits all at once. This is a
fast way of multiplying two numbers since all it takes is the time to propagate through the gates that
form the multiplication array.
Consider multiplication of two 2-bit numbers: Multiplicand = b1b0, Multiplier = a1a0, Product = c3c2c1c0
• Since multiplication of
two bits is identical to
AND operation and hence
can be implemented with
AND gate.
• In the diagram, partial
products and formed and
added by means of HA
(half adders).
A combinational circuit binary multiplier with more bits can be constructed in similar fashion. For j
multiplier bits and k multiplicand bits, we need j*k AND gates and (j-1) k-bit adders to produce a product
of j+k bits.
Page 6
Division Algorithms
Division of fixed-point binary numbers in signed-magnitude representation is done with successive
compare, shift and subtract operations.
Example:
Divide Overflow
Division operation may result in a quotient with an overflow when working with finite size registers.
Storing divisor in n-bit resister and dividend in 2 n-bit registers, then if quotient occupies n+1 bits,
we say divide-overflow has occurred (since n+1 bit quotient can not be stored in standard n-bit Q-
register and/or memory word).
Talking about special case: size (dividend) = 2 * size (divisor). Divide-overflow condition will occur if
high-order half bits of the dividend >= divisor. This condition is detected by DVF (Divide-overflow
Flip-flop).
Handling of overflow: its programmer’s responsibility to detect DVF and take corrective measure. The
best way is to use floating point data.
Page 7
B: Divisor, AQ: Dividend
If A>=B (oh yes, magnitudes are compared
subtracting one from another and testing E flip-
flop), DVF is set and operation is terminated
prematurely. If A<B, no overflow and dividend
is restored by adding B to A (since B was
subtracted previously to compare magnitudes).
Division starts by left shifting AQ (dividend)
with high order bit shifted to E. Then E=1, EA>B
so B is subtracted from EA and Qn is set to 1. If
E=0, result of subtraction is stored in EA, again
E is tested. E=1 signifies A>=B, thus Qn is set to
1 and E=0 denotes A<B, so original number is
restored by adding B to A and we leave 0 in Qn.
Process is repeated again with register A
holding partial remainder. After n-1 times Q
contains magnitude of Quotient and A contains
remainder. Quotient sign in Qs and remainder
sign in As.
Page 8
Other division algorithms
Method described above is restoring method in which partial remainder is restored by adding the
divisor to the negative result. Other methods:
Comparison method: A and B are compared prior to subtraction. Then if A>=B, B is subtracted form A. if
A<B nothing is done. The partial remainder is then shifted left and numbers are compared again.
Comparison inspects end-carry out of the parallel adder before transferring to E.
Nonrestoring method: In contrast to restoring method, when A-B is negative, B is not added to restore
A but instead, negative difference is shifted left and then B is added. How is it possible? Let’s argue:
In flowchart for restoring method, when A<B, we restore A by operation A-B+B. Next tine in a loop,
this number is shifted left (multiplied by 2) and B subtracted again, which gives: 2(A - B + B) – B =
2A-B.
In Nonrestoring method, we leave A-B as it is. Next time around the loop, the number is shifted left
and B is added: 2(A-B)+B = 2A-B (same as above).
10.5 solution
10.15 solution:
Page 9
Page 10