csnotes/cst337/lec/lec10.md
2018-10-03 00:33:41 -07:00

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

fig0

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

Next we'll add on the xor. AGAIN: try to do this on your own, the main hint I'll give here is: the current mux needs to be changed.

fig2

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 dhowever, we can also not the result of the xor and get the same result.

fig3

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

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.