1.6 KiB
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
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!
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.
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.
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.
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.