Verilog 中的 for 循环如何执行?
Verilog 中的 for 循环是否并行执行?我需要多次调用一个模块,但它们必须同时执行。我没有将它们一一写出来,而是考虑使用 for 循环。效果会一样吗?
Do for loops in Verilog execute in parallel? I need to call a module several times, but they have to execute at the same time. Instead of writing them out one by one, I was thinking of using a for loop. Will it work the same?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Verilog 描述硬件,因此在这种情况下考虑执行循环或调用模块是没有意义的。如果我正确理解您问题的意图,您希望拥有具有不同输入和输出的同一模块的多个实例。
要实现此目的,您可以使用 Verilog 的 生成语句 自动生成实例化。
您还可以使用 Emacs 优秀的 auto_template 功能 a href="http://www.veripool.org/wiki/verilog-mode" rel="nofollow noreferrer">verilog 模式。我更喜欢这种方法,因为每个实例化都明确地出现在我的源代码中,并且我发现更容易检测错误。
Verilog describes hardware, so it doesn't make sense to think in terms of executing loops or calling modules in this context. If I understand the intent of your question correctly, you'd like to have multiple instantiations of the same module with distinct inputs and outputs.
To accomplish this you can use Verilog's generate statements to generate the instantiations automatically.
You can also use the auto_template functionality in Emacs' excellent verilog-mode. I prefer this approach as each instantiation appears explicitly in my source code and I find it easier to detect errors.
正如 jlf 回答的那样,您正在寻找生成语句。您可以使用 for 循环来建模组合逻辑,例如遍历寄存器中的所有位并计算输出。这将位于测试平台中的始终块甚至初始块中。
As jlf answered, you're looking for a generate statement. You would use a for-loop to model combinational logic, such as going through all of the bits in a register and computing an output. This would be in an always block or even an initial block in your testbench.