I created a worksheet to help guide my students to realize that combining four simple Boolean/binary operations (zeroing, bitwise negation, summing, anding) in a two's complement number system can yield eighteen functions (per figure 2.6).
This is to help assert the path of using the simple operations as mentioned in the implementation hint on page 39, as opposed to just diving in trying to implement the higher-level functions as they know them. For example, a student may try to use Inc16 to implement x+1 rather than using the combined simple operations in figure 2.6. Although this may be possible, I want to be sure the student embraces the underlying design of the ALU and has a nice "Aha!" moment.
I'll let you know how well this works in practice in February 2010.
I had the same problem at first. (That's why I ended up here. )
After some time I finagled it out though:
Each "exercise" in the worksheet corresponds to one line in the ALU-truth-table.
So the first example, where the solution is given, corresponds to the line where f(x,y) is supposed to yield 0.
The next where f(x,y) yields 1 ... and so on.
(And rereading the text in the alu-worksheet it says so right from the beginning )
BTW: Like probably many others in the forum I'm going through the book all on my own - with no background knowledge in EE or such. I therefore absolutely depend on the forum. Without you guys I probably would have been lost already in ch. 1. So - thanks a lot for all the summaries, helpful hints, tables and other tools you come up with!!!
This worksheet was indeed great for seeing the patterns in the input bits to perform the various operations.
However, the subtraction math just isn't clicking for me. For example, to perform x-y I immediately thought you would change it to x+(-y). In other words, you would make y negative and then add it to x. Instead, we modify x (negate it bitwise) add it to y, and then negate the answer. I don't see how this set of steps maps to the 2's complement math described in the book.
Mark, thanks a million for your quick and informative response. The proof you provided for x-y could not have been clearer. I never would have arrived at that myself, but it helps me a great deal to see it in action.
If the authors of the book are reading this, please include the following info that Mark gave in the next edition. It would make the steps of the operations MUCH clearer.
First, here's an identity for two's complement numbers that's very useful for proving ALU computations:
-x = (~x)+1
and a corollary:
~x = (-x)-1 = -(x+1)
Just want to second this, thanks for sharing, and a general thanks to both you and cadet1620 for the help you provide in the forum :)
As KitN, I also implemented the ALU without using the worksheet. I did it by just following the implementation comments in the stub HDL file in the order they were listed.
Looking at the other postings in this subforum, it seems like I have used the most common implementation (15 parts in total, 6 Mux16, four parts for the zr status)
However, I didn't really get all the nuances in the inner working of the ALU, I just followed the implementation comments and the resulting ALU passed the test. A lightbulb kind of lit up in my head when I read cadet1620's post in this thread about computing x-y. The work sheet will be a good tool in understanding how all the other computations are done in the ALU.