Re: Figuring out zr
Posted by mbm29414 on Jan 25, 2011; 1:08pm
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Figuring-out-zr-tp2326310p2329182.html
That's what I thought, but the code in the file from Google Code seemed to indicate you could.
Here's the Google Code section:
-----------------------------------------------------
/** out2 is the same as the value passed to out
* ng1 is the same as the value passed to ng
*/
Add16(a[0..15]=out2, b[0..15]=true, out[0..15]=out3, out[15]=out315);
Not(in=ng1, out=ngcomp);
And(a=ngcomp, b=out315, out=zr);
So, in the code above, the output value is added to '1111111111111111'. Then, the result is stored into a 16-bit bus and the left-most digit is stored into a 1-bit bus. (Side question: As far as I can tell, out3 is never used; is it only "produced" because you have to have a "full" out before grabbing part of it? Could you not just leave out the "out[0..15]=out3" part?) Then, ng1 (the left-most digit of the output value) is negated and zr is set to ngcomp*out315. This doesn't make sense to me, but I was thinking that these posts are from the authors.
The thought I've had was something like this:
-----------------------------------------------------
Add16(a=outValue, b[0..15]=true, out=allOnesTest);
And16Way(in=allOnesTest, out=zr);
Of course, we never made an And16Way chip, but I'm thinking along those lines because the first line (or something like it) was in the Google Code file.
If I were to do it from scratch (using the hint you gave), I'd probably come up with this:
-----------------------------------------------------
Or8Way(in=outValue[0..7], out=firstPartOr);
Or8Way(in=outValue[8..15], out=secondPartOr);
Or(a=firstPartOr, b=secondPartOr, out=orOut);
Not(in=orOut, out=zr);
Is there a better/more efficient way to do this? Am I at least on the right track?