A | B | C | | Y1 | Y0 |
0 | 0 | 0 | | 0 | 0 |
0 | 0 | 1 | | 0 | 1 |
0 | 1 | 0 | | 0 | 1 |
0 | 1 | 1 | | 1 | 0 |
1 | 0 | 0 | | 0 | 1 |
1 | 0 | 1 | | 1 | 0 |
1 | 1 | 0 | | 1 | 0 |
1 | 1 | 1 | | 1 | 1 |

# Four-bit Adder
## Demo: constructing a 4-bit adder from 1-bit full adders

[Adder test vector](../../assets/adder4bit_test_vector.txt)
# ALU
## The ALU
- What does ALU stand for?
+ Arithmetic Logic Unit
-
What does an ALU do?
+ Does all the logical and arithmetic operations of the CPU
## Basic ALU
- The simplest ALU conceivable is one that only operates on two 1-bit inputs and can perform only two operations: **AND** and **OR**
```py
def basic_alu(a, b, op):
if op == "0":
return (a and b)
else:
return (a or b)
```
-
Let's implement this in Logisim!
### Exercise: Enhance the Basic ALU
1. make it work on 4-bit values
2. add operations for XOR and NOT
- you will need a bigger multiplexor
- NOT only works on **A** - ignore **B**
3. Can you include your 4-bit adder?
# Subtraction
## Subtraction
- You can use the same adder circuitry to support subtraction
- convert **B** into it's negative value
- flip all the bits (NOT gate)
- add 1 (give a 1 to **Cin**)
[Adder/Subtractor test vector](../../assets/addersubtractor4bit_test_vector.txt)
## Supporting `slt`
You can even use your adder for *set on less than*
- set the adder to do subtraction
- look at the highest bit of the result
+ if it is 1, then the subtraction result was negative, so set result to 1
+ if it is 0, then the subtraction result was not negative, so set result to 1