How to implement And16 chip?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to implement And16 chip?

hdllearn
Hi All,

Please Help!!!

I have been able to implement And gate, Or gate, Not gate from Nand gate.

However, I am unable to implement the And16 gate as I cannot find the syntax to do so. I have tried the following but none of these work:

1:
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/1/And16.hdl
/**
 * 16-bit And gate:
 * for i = 0, ..., 15:
 * out[i] = a[i] And b[i]
 * select Format in Hardware simulator to binary
 */
CHIP And16 {
    IN a[16], b[16];
    OUT out[16];
   
   PARTS:
   And(a[16]=a[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15], b[16]=b[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15], out[16);
   
}

2:
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/1/And16.hdl
/**
 * 16-bit And gate:
 * for i = 0, ..., 15:
 * out[i] = a[i] And b[i]
 * select Format in Hardware simulator to binary
 */
CHIP And16 {
    IN a[16], b[16];
    OUT out[16];
   
   PARTS:
   And(a[0..16]=0, b[0..16]=1, out[16]);

}

3:
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/1/And16.hdl
/**
 * 16-bit And gate:
 * for i = 0, ..., 15:
 * out[i] = a[i] And b[i]
 * select Format in Hardware simulator to binary
 */
CHIP And16 {
    IN a[16], b[16];
    OUT out[16];
   
   PARTS:
   And(a=a[0], b=b[0], out);
   And(a=a[1], b=b[1], out);
   And(a=a[2], b=b[2], out]);
   And(a=a[3], b=b[3], out);
   And(a=a[4], b=b[4], out);
   And(a=a[5], b=b[5], out);
   And(a=a[6], b=b[6], out);
   And(a=a[7], b=b[7], out);
   And(a=a[8], b=b[8], out);
   And(a=a[9], b=b[9], out};
   And(a=a[10], b=b[10], out);
   And(a=a[11], b=b[11], out);
   And(a=a[12], b=b[12], out);
   And(a=a[13], b=b[13], out);
   And(a=a[14], b=b[14], out);
   And(a=a[15], b=b[15], out);
 
}


John
Reply | Threaded
Open this post in threaded view
|

Re: How to implement And16 chip?

WBahn
Administrator
All three have issues.

It appears that you are practicing design by happening -- try random things and hope that, somehow, something will just happen to work.

Which version of the text are you using? If the 2nd Edition, be sure to study (not just skim) Appendix 2.

The And gate is a two-input, one-output part. Your first two attempts completely fail to recognize this. In addition, your first one has a syntax error ("...  out[16);" ).

Your third attempt is close, but in addition to another syntax error on one of the lines, you are connecting a one-bit output from the And gate to the entire sixteen-bit chip output.

Look at the comment:

* out[i] = a[i] And b[i]


Reply | Threaded
Open this post in threaded view
|

Re: How to implement And16 chip?

hdllearn
In reply to this post by hdllearn
Hi WBahn,

thanks for your remarks. Below is my first attempt on the list. When it did not work, I tried the others listed as 1 and 2. So I tried to use the array as in C++.

But this still does not work. I cannot find the errors. Please help!!!

// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/1/And16.hdl
/**
 * 16-bit And gate:
 * for i = 0, ..., 15:
 * out[i] = a[i] And b[i]
 * Format in Hardware simulator to binary
 */
CHIP And16 {
    IN  a[16], b[16];
    OUT out[16];
   
   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]);
   And(a=a[4], b=b[4], out=out[4]);
   And(a=a[5], b=b[5], out=out[5]);
   And(a=a[6], b=b[6], out=out[6]);
   And(a=a[7], b=b[7], out=out[7]);
   And(a=a[8], b=b[8], out=out[8]);
   And(a=a[9], b=b[9], out=out[9];
   And(a=a[10], b=b[10], out=out[10]);
   And(a=a[11], b=b[11], out=out[11]);
   And(a=a[12], b=b[12], out=out[12]);
   And(a=a[13], b=b[13], out=out[13]);
   And(a=a[14], b=b[14], out=out[14]);
   And(a=a[15], b=b[15], out=out[15]);
 
}
   
   
   
John
Reply | Threaded
Open this post in threaded view
|

Re: How to implement And16 chip?

hdllearn
In reply to this post by hdllearn
I also cannot find the .out file to check for errors. Can you please help?
John
Reply | Threaded
Open this post in threaded view
|

Re: How to implement And16 chip?

hdllearn
In reply to this post by hdllearn
Hi WBahn

thanks for your help, working now.
John
Reply | Threaded
Open this post in threaded view
|

Re: How to implement And16 chip?

WBahn
Administrator
Glad you found and fixed the issue.

What was it (so that others can learn from your experience).

Where the files in the correct folder?
Reply | Threaded
Open this post in threaded view
|

Re: How to implement And16 chip?

hdllearn
Typos
John
Reply | Threaded
Open this post in threaded view
|

Re: How to implement And16 chip?

hdllearn
files were in the correct folders.
John