Login  Register

And16

Posted by DK3250 on Mar 03, 2021; 9:52pm
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/And16-tp4035770.html

To simplify test I start with And4 like this:

CHIP And16 {
    IN a[4], b[4];
    OUT out[4];

    PARTS:
    And(a=a[0], b=b[0], out=out[0]);
    And(a=a[1], b=b[1], out=out[1]);
    And(a=a[2], b=b[2], out=out[2]);
    And(a=a[3], b=b[3], out=out[3]);
   
}
It works - in the sense it compiles and run without errors.
But I'm still perplexed:
I expect the two input to be list like "1101" and "0101" - but not matter my input the simulator turns it to "1". Output also becomes a single bit.
Can someone explain?
Next question: Is this really the simplest way to specify And16? 16 lines of highly repetitive code. Can I use some kind of loop here?