Arithmetic-Logic Units The Four-Bit Adder: S A + B + Ci
Arithmetic-Logic Units The Four-Bit Adder: S A + B + Ci
But by changing what goes into the adder inputs A, B and CI, we can
change the adder output S.
This is also what we did to build the combined adder-subtractor circuit.
10/6/2003
Arithmetic-logic units
10/6/2003
Arithmetic-logic units
10/6/2003
Here the signal Sub and some XOR gates alter the adder inputs.
When Sub = 0, the adder inputs A, B, CI are Y, X, 0, so the adder
produces G = X + Y + 0, or just X + Y.
When Sub = 1, the adder inputs are Y, X and 1, so the adder output
is G = X + Y + 1, or the twos complement operation X - Y.
10/6/2003
Arithmetic-logic units
Arithmetic-logic units
A = 1111 (-1), B = X, CI = 0
A = 0000, B = X, CI = 0
This is almost the same as the
increment function!
10/6/2003
Arithmetic-logic units
10/6/2003
Arithmetic-logic units
The role of CI
The transfer and increment operations have the same A and B inpu ts,
and differ only in the CI input.
In general we can get additional functions (not all of them usef ul) by
using both CI = 0 and CI = 1.
Another example:
Twos-complement subtraction is obtained by setting A = Y, B = X,
and CI = 1, so G = X + Y + 1.
If we keep A = Y and B = X, but set CI to 0, we get G = X + Y. This
turns out to be a ones complement subtraction operation.
10/6/2003
Arithmetic-logic units
S2
S1
S0
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
10/6/2003
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
10/6/2003
(transfer)
(increment)
(add)
(1C subtraction)
(2C subtraction)
(decrement)
(transfer)
X
X
X
X
X
X
X
X
0
1
0
1
0
1
0
1
Arithmetic-logic units
S2
S1 A
0
0
1
1
0
1
0
1
10/6/2003
Arithmetic-logic units
10/6/2003
S2
S1
0
0
1
1
0
1
0
1
0000
Y
Y
1111
S1
Yi
Ai
0
0
0
0
0
1
0
0
0
0
1
1
0
1
0
1
1
1
0
0
0
1
1
0
1
1
1
1
0
1
1
1
Arithmetic-logic units
10
0000
Y
Y
1111
(1C subtraction)
(2C subtraction)
(decrement)
(transfer)
This second table shows what the adders inputs should be for each of
our eight desired arithmetic operations.
Adder input CI is always the same as selection code bit S 0.
B is always set to X.
A depends only on S2 and S1.
These equations depend on both the desired operations and the
assignment of selection codes.
Selection code
S2
S1
S0
(transfer)
(increment)
(add)
Arithmetic-logic units
Arithmetic operation
X
X+1
X+Y
X+Y+1
X + Y
X + Y + 1
X1
X
S2
0
1
0
0
Yi
S1
1
0
1
1
Ai = S 2Yi + S 1Yi
11
10/6/2003
Arithmetic-logic units
12
Bitwise operations
1 0 1 1
AND 1 1 1 0
1 0 1 0
Most computers also support logical operations like AND, OR and NOT,
but extended to multi-bit words instead of just single bits.
To apply a logical operation to two words X and Y, apply the operation
on each pair of bits Xi and Y i:
OR
1 0 1 1
1 1 1 0
1 1 1 1
1 0 1 1
XOR 1 1 1 0
01 01
They are not the same as the operators &&, || and !, which treat each
integer as a single logical value (0 is false, everything else is true):
& (AND)
13 & 25 = 9
Arithmetic-logic units
13
10/6/2003
0. 0. 0. 31 = 00000000.00000000.00000000.00011111
192.168. 10. 63 = 11000000.10101000.00001010.00111111
10/6/2003
Arithmetic-logic units
15
Arithmetic-logic units
14
S1
S0
Output
0
0
1
1
0
1
0
1
Gi = X iYi
Gi = X i + Y i
G i = X i Yi
Gi = X i
10/6/2003
Arithmetic-logic units
16
Inputs:
X (4 bits)
Y (4 bits)
S (2 bits)
Outputs:
G (4 bits)
10/6/2003
~ (NOT)
because
^ (XOR)
Arithmetic-logic units
because
13 && 25 = 1
10/6/2003
| (OR)
17
10/6/2003
Arithmetic-logic units
18
S3
S2
S1
S0
Operation
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
G=X
G=X+1
G=X+Y
G=X+Y+1
G = X + Y
G = X + Y + 1
G=X1
G=X
1
1
1
1
x
x
x
x
0
0
1
1
0
1
0
1
G = X and Y
G = X or Y
G=XY
G = X
4
4
10/6/2003
Arithmetic-logic units
19
10/6/2003
Arithmetic-logic units
20
Both the arithmetic unit and the logic unit are active and produce
outputs.
The mux determines whether the final result comes from the
arithmetic or logic unit.
The output of the other one is effectively ignored.
Our hardware scheme may seem like wasted effort, but its not really.
Deactivating one or the other wouldnt save that much time.
We have to build hardware for both units anyway, so we might as
well run them together.
This is a very common use of multiplexers in logic design.
10/6/2003
Arithmetic-logic units
21
Arithmetic summary
10/6/2003
Arithmetic-logic units
23
10/6/2003
Arithmetic-logic units
22