Work with arrays in HDL

How to use arrays (representing buses) in HDL?

For example, I have the following code:

/** * 16-bit bitwise And: * for i = 0..15: out[i] = (a[i] and b[i]) */ CHIP And16 { IN a[16], b[16]; OUT out[16]; PARTS: // Put your code here: } 

Assuming I already have And , how could I implement this?

I would prefer not to have the following:

 And(a=a[0],b=b[0],out=out[0]); And(a=a[1],b=b[1],out=out[1]); ... And(a=a[14],b=b[14],out=out[14]); And(a=a[15],b=b[15],out=out[15]); 
+5
source share
1 answer

There are no arrays in HDL. Section 1.3 of nand2tetris companion book , he says

Since we already know how to implement elementary versions of these gates, implementing their n-ary versions is simply a matter of building arrays of n elementary gates, each of which works separately on its own bits. This implementation task is rather boring , but it will carry its weight when these multi-digit gates are used in more complex circuits, as described in subsequent chapters.

So, in addition to writing a trivial script in Python, to avoid everything that was printed, you did not miss anything.

+1
source

Source: https://habr.com/ru/post/1261621/


All Articles