gpt4 book ai didi

arrays - 在 HDL 中处理数组

转载 作者:行者123 更新时间:2023-12-02 13:01:38 25 4
gpt4 key购买 nike

如何在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com