csnotes/337/lec/lec10.md
2019-09-25 18:49:13 -07:00

42 lines
1.6 KiB
Markdown

# lec11
At this point I'l mention that just reading isn't going to get you anywhere, you have to try things, and give it a real earnest attempt.
__ALU:__ Arithmetic Logic Unit
## Building a 1-bit ALU
![fig0](../img/alu.png)
First we'll create an example _ALU_ which implements choosing between an `and`, `or`, `xor`, or `add`.
Whether or not our amazing _ALU_ is useful doesn't matter so we'll go one function at a time(besides `and/or`).
First recognize that we need to choose between `and` or `or` against our two inputs A/B.
This means we have two inputs and/or, and we need to select between them.
_Try to do this on your own first!_
![fig1](../mg/fig1llec11.png)
Next we'll add on the `xor`.
Try doing this on your own but as far as hints go: don't be afraid to make changes to the mux.
![fig2](../img/fig2lec11.png)
Finally we'll add the ability to add and subtract.
You may have also noted that we can subtract two things to see if they are the same however, we can also `not` the result of the `xor` and get the same result.
![fig3](../img/fig3lec11.png)
At this point our _ALU_ can `and`, `or`, `xor`, and `add`/`sub`.
The mux will choose one which logic block to use; the carry-in line will tell the `add` logic block whether to add or subtract.
Finally the A-invert and B-invert line allow us to determine if we want to invert either A or B (inputs).
## N-bit ALU
For sanity we'll use the following block for our new ALU.
![fig4](../img/fig4lec11.png)
Note that we are chaining the carry-in's to the carry-out's just like a ripple adder.
also each ALU just works with `1` bit from our given 4-bit input.