Dealing with arrays in HDL
Asked Answered
W

2

9

How does one use arrays (representing busses) 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 have And already implemented, how could I implement this?

I'd rather not 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]);
Waterborne answered 21/12, 2016 at 5:0 Comment(2)
If, and I'm pretty sure this is, related to nand2tetris course, tag this question accordingly. If this is nand2tetris hdl version, then you will have to deal with buses manually, as in your example.Endpaper
@Endpaper -- Yes, you're correct. I didn't want it to sound like HW-help (which it isn't, I assure you) and I thought the source was irrelevant. Also, I assumed that HDL was the name of a language, not a classification of different languages. My apologies. Thanks, though!Waterborne
L
5

There are no arrays in HDL. In section 1.3 of the nand2tetris companion book, he says

Since we already know how to implement the elementary versions of these gates, the implementation of their n-ary versions is simply a matter of constructing arrays of n elementary gates, having each gate operate separately on its bits. This implementation task is rather boring, but it will carry its weight when these multi-bit gates are used in more complex chips, as described in subsequent chapters.

So besides writing a trivial script in Python to avoid all that typing, you're not missing anything.

Lendlease answered 20/1, 2017 at 11:56 Comment(1)
In the second edition of the book, this passage appears in section 1.5.2. The text now says: “The resulting HDL code will be somewhat boring and repetitive (using copy-paste), but it will carry its weight when these multi-bit gates are used in the construction of more complex chips later in the book.”Nanice
P
-2

You can write the code in c(because it's the closer language to hdl that has for loops) then you can use any c to hdl tool to use your for loop in c to get your chip running without repetting the same code 16 times

Punctual answered 27/1 at 14:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.