The ALU and Basic Arithmetic
Last Edit November 1, 1996; May 1, 1999 ; July 15, 2001
Arithmetic  General
The Am2901 and Am2903 perform two's complement arithmetic.
Two's complement notation is a weighted binary code, where the sign
bit (most significant bit) has a negative weight. For example, for
an 8bit system
The negative number encoding can be formed by logically complementing
all bits abd adding 1 to the encoding of the positive number.
The advantage of the two's complement number system is that there
is a single zero. The numbers are normally considered
to be binary fractions, so that a positive number is less than 1
and a negative number is greater than 1.
Addition
Addition is performed as a straightforward binary
addition, with the sign of the result dependent on the signs of
the operands.
For two positive numbers the sign is positive, and
for two negative numbers it is negative. A check should always be
made for overflow, which is possible when the sums of the magnitudes
exceed 1. The Am2901 and the Am2903 both provide an overflow pin.
Subtraction
SUbtraction is processed in the same manne as addition,
i.e., complement the subtrahend and add. Both the Am2901 and Am2903
provide two subtraction operations, A  b and B  A.
Multiplication
The most difficult of the arithmetic operations so
far is multiplication.
Unsigned Binary
To perform B x A in two's complement, where the numbers
are either both unsigned or both positive, the procedure is the
same as for binary multiplication. The multiplier is examined bit
by bitright to left (least significant to most significant bit)
to determine if the multiplicand is to be added to the partial result.
If so, the multiplicand is aligned so that the least significant
is under the multiplier bit's position, as shown in Figure 65.
Figure 65 Unsigned binary multiplication
Multiplicand Negative
When the multiplicand is negative, B * (A), sign
extension of the multiplicand is used to form the first partial
product, maintaining the 2n length of the magnitude. Each
time the multiplicand is added, the sign extension form is used.
The sign of the multiplicand is the sign of the result.
Multiplier Negative
When the multiplier is negative, (B) * A, the multiplication
proceeds as for the unsigned or bothpositive case, except that
at the end, the two's complement of A, the multiplicand, is added
aligned on the binary points and not by placing the least significant
bit of A under the sign bit of B, the multiplier.
Both Negative
Where both numbers are negative, the multiplicand
is signextended and added as for the multiplicandnegative algorithm.
At the end, the two's complement of the multiplicand is added, properly
aligned as for the multipliernegative alforithm.
Result
The point of reviewing the various cases was to produce
a common algorithm (method 1, Flores, Computer Arithmetic):
 the leftmost bits are a function of the sign of the multiplicand
 partial product addition is required with alignment
 the two's complement of the multiplicand is added at the end
if the sign of the multiplier is negative.
