Re: Getting started with ALU
Posted by Jack Draak on Feb 20, 2018; 6:14pm
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Getting-started-with-ALU-tp4030218p4031783.html
After browsing through ~a dozen posts here: Thanks! What a great community you've got here! This is some great advice. I have to admit, that at some points I found myself completely stumped by this course (i.e. trying to design my first MUX). Had I found this forum sooner, I'm sure it would have helped immensely.
I feel I have a bit of advantage though, as I have a long history of tinkering with various programming languages to do fairly simple things. Still, when I was approaching my ALU I was feeling similarly to the OP.... Where do I even start? How could I possibly truth-table a solution here, or draft a k-map for 22 inputs and 18 outputs? Well, when my programmer brain took a close look at the stub file, what seemed fairly obvious was, as Mark point's out, that no matter what the flag inputs are set to, each operation must be performed and then the flag can be used to select which of two states to "push down the wire" so to speak.
So, in the end (and as usual) the majority of my trouble building my ALU came from typos (and learning the syntax to output specific signals more than once from given chips). I also had a few stumbles around the specific operations, for example the book tells us,
"to obtain the code of -x from the code of x, leave all the trailing (least significant) 0’s and the first least significant 1 intact, then flip all the remaining bits (convert 0’s to 1’s and vice versa). An equivalent shortcut, which is easier to implement in hardware, is to flip all the bits of x and add 1 to the result."
I interpret this to mean that if I have a 16-bit number (x) on my bus (in 2's complement format) I can shove it through a Not16 then an Inc16 and et viola! -x..... For the benefit of those who have yet to do their ALU I don't want to say much more about that, but frankly, although my ALU now passes it's tests, I'd love to grok either the statement from the book (because apparently I don't) or what magic I've crafted that let's me do it differently that I've just described.
But again, thanks to the community for sharing and helping each other here. I may not have found it soon enough to help with my MUX, but there's no doubt I'll be looking for more help before I finish this course.