Login  Register

Re: Shortening ALU Code

Posted by cadet1620 on May 19, 2011; 10:38am
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Shortening-ALU-Code-tp2960233p2960811.html

Zebo wrote
I tried to avoid the "sub bus of an internal node" problem and just use the final out to make my flaggers but OF COURSE another error came up.

Here is the code:
    ...
    Mux16(a=d, b=notd, sel=no, out[0..15]=out[0..15]);
    Or8Way(in=out[0..7], out=p);
    Or8Way(in=out[8..15], out=q);
    ...
Am I going to have to just do a completely different setup or is there a way to make this work?
You're very close.  The clue that you're missing is that you can connect more than one bus or wire to an output:
    Mux16(a=d, b=notd, sel=no, out=out, out[0..7]=lowbyte, etc.);
    Or8Way(in=lowbyte, out=p);
    Or8Way(in=highbyte, out=q);
And you get the ng flag for free this way, too.

--Mark

[Plese edit your post to remove the working part of your ALU.  It's better for people to design it themselves rather than find it by searching the forum.]