arrays - 在 HDL 中处理数组

标签 arrays syntax hdl bus nand2tetris

如何在 HDL 中使用数组(代表总线)?

例如,我有以下代码:

/**
 * 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:
}

假设我已经实现了And,我该如何实现它?

我不想有以下内容:

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]);

最佳答案

There are no arrays in HDL.nand2tetris companion book 的第 1.3 节中,他说

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.

因此,除了用 Python 编写一个简单的脚本来避免所有输入之外,您不会遗漏任何内容。

关于arrays - 在 HDL 中处理数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41255404/

相关文章:

hdl - 我的 DMux 4 方式有什么问题?

testing - Isim 未测试测试夹具中的所有位

java - 我试图从 3 个字符串数组中随机选择元素?

java - 将 int 转换为数组而不将其转换为 String

python - 将伪代码翻译成Python?

swift - 为什么函数调用需要参数名称,而分配给变量的函数不允许?

arrays - 我在对象数组上使用 ngFor,而在 html 中数据未显示

javascript - 输出javascript数组的内容

php - if () { } 和 if () 的区别 : endif;

verilog - 在verilog中使用 '<='运算符