Professional Documents
Culture Documents
Addition
Adding unsigned numbers in binary is quite easy. Recall that with 4 bit numbers we
can represent numbers from 0 to 15. Addition is done exactly like adding decimal
numbers, except that you have only two digits (0 and 1). The only number facts to
remember are that
The only difficulty adding unsigned numbers occurs when you add numbers that are too large. Consider
13+5.
The result is a 5 bit number. So the carry bit from adding the two most significant bits
represents a results that overflows (because the sum is too big to be represented with
the same number of bits as the two addends).
Adding signed numbers is not significantly different from adding unsigned numbers. Recall that signed 4
bit numbers (2's complement) can represent numbers between -8 and 7. To see how this addition
works, consider three examples.
Decimal Signed Binary
1110 (carry)
-2 1110
+3 +0011
1 0001
In this case the extra carry from the most significant bit has no meaning. With signed numbers there are
two ways to get an overflow -- if the result is greater than 7, or less than -8. Let's consider these
occurrences now.
Obviously both of these results are incorrect, but in this case overflow is harder to
detect. But you can see that if two numbers with the same sign (either positive or
negative) are added and the result has the opposite sign, an overflow has occurred.
Typically DSP's, including the 320C5x, can deal somewhat with this problem by
using something called saturation arithmetic, in which results that result in overflow
are replaced by either the most positive number (in this case 7) if the overflow is in
the positive direction, or by the most negative number (-8) for overflows in the
negative direction.
Adding fractions
There is no further difficult in adding two signed fractions, only the interpretation of
the results differs. For instance consider addition of two Q3 numbers shown (compare
to the example with two 4 bit signed numbers, above).
If you look carefully at these examples, you'll see that the binary representation and
calculations are the same as before, only the decimal representation has changed. This
is very useful because it means we can use the same circuitry for addition, regardless
of the interpretation of the results.
Multiplication
Multiplication is different than addition in that multiplication of an n bit number by an m bit number
results in an n+m bit number. Let's take a look at an example where n=m=4 and the result is 8 bits
Decimal Binary
1010
x0110
0000
10
1010
x6
1010
60
+0000
0111100
In this case the result was 7 bit, which can be extended to 8 bits by adding a 0 at the left. When
multiplying larger numbers, the result will be 8 bits, with the leftmost set to 1, as shown.
Decimal Binary
1101
x1110
0000
13
1101
x14
1101
182
+1101
10110110
As long as there are n+m bits for the result, there is no chance of overflow. For 2 four
bit multiplicands, the largest possible product is 15*15=225, which can be represented
in 8 bits.
There are many methods to multiply 2's complement numbers. The easiest is to
simply find the magnitude of the two multiplicands, multiply these together, and then
use the original sign bits to determine the sign of the result. If the multiplicands had
the same sign, the result must be positive, if the they had different signs, the result is
negative. Multiplication by zero is a special case (the result is always zero, with no
sign bit).
Multiplying fractions
As you might expect, the multiplication of fractions can be done in the same way as
the multiplication of signed numbers. The magnitudes of the two multiplicands are
multiplied, and the sign of the result is determined by the signs of the two
multiplicands.
The other difficulty is that multiplying two Q3 numbers, obviously results in a Q6 number, but we have 8
bits in our result (since we are multiplying two 4 bit numbers). This means that we end up with two bits
to the left of the decimal point. These are sign extended, so that for positive numbers they are both
zero, and for negative numbers they are both one. Consider the case of multiplying -1/2 by -1/2 (using
the method from the textbook):
On a 16 bit DSP two Q15 numbers are multiplied to get a Q30 number with two sign
bits. On the 320C50 there are two ways to accomplish this. The first is to use the p-
scaler immediately after the multiplier, or the postscaler after the accumulator. to shift
the result to the left by one