使用 Wire 或 reg 进行输入或输出

发布于 2024-10-24 06:01:01 字数 78 浏览 1 评论 0原文

当您将某些内容声明为输入或输出时,您如何知道是否还必须将其声明为 reg 还是 wire

When you declare something as input or output, how do you know if you have to also declare it as a reg or a wire?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

伏妖词 2024-10-31 06:01:01

regwire 指定如何分配对象,因此仅对输出有意义。

如果您打算在顺序代码中分配输出,例如在 always 块中,请将其声明为 reg (这实际上是 Verilog 中“变量”的用词不当) 。否则,它应该是wire,这也是默认值。

reg and wire specify how the object will be assigned and are therefore only meaningful for outputs.

If you plan to assign your output in sequential code,such as within an always block, declare it as a reg (which really is a misnomer for "variable" in Verilog). Otherwise, it should be a wire, which is also the default.

喜爱纠缠 2024-10-31 06:01:01

output reg foo 只是 output foo_wire 的简写;注册富;分配 foo_wire = foo。当您打算注册该输出时,它会很方便。我认为 input reg 对于 module (也许是 task)没有意义。 输入线输出线输入输出相同:只是更明确。

An output reg foo is just shorthand for output foo_wire; reg foo; assign foo_wire = foo. It's handy when you plan to register that output anyway. I don't think input reg is meaningful for module (perhaps task). input wire and output wire are the same as input and output: it's just more explicit.

水染的天色ゝ 2024-10-31 06:01:01

您使用的 Verilog 代码编译器将决定您必须做什么。如果使用非法语法,则会出现编译错误。

仅当使用“过程赋值”进行赋值时,output 也必须声明为 reg。例如:

output reg a;
always @* a = b;

无需将 output 声明为 wire

无需将input声明为wirereg

The Verilog code compiler you use will dictate what you have to do. If you use illegal syntax, you will get a compile error.

An output must also be declared as a reg only if it is assigned using a "procedural assignment". For example:

output reg a;
always @* a = b;

There is no need to declare an output as a wire.

There is no need to declare an input as a wire or reg.

情独悲 2024-10-31 06:01:01

在数字电路域中看到它

  1. A Wire 将创建一个电线输出,只能使用分配语句将其分配给任何输入,因为分配语句创建端口/引脚连接,并且电线可以连接到端口/引脚
  2. A reg 将创建一个寄存器( D FLIP FLOP)根据灵敏度列表获取或接收输入,它可以是时钟(上升或下降)或组合边沿。

所以这完全取决于您的使用是否需要创建一个寄存器并根据敏感度列表勾选它或者您想要创建一个端口/引脚分配

seeing it in digital circuit domain

  1. A Wire will create a wire output which can only be assigned any input by using assign statement as assign statement creates a port/pin connection and wire can be joined to the port/pin
  2. A reg will create a register(D FLIP FLOP ) which gets or recieve inputs on basis of sensitivity list either it can be clock (rising or falling ) or combinational edge .

so it completely depends on your use whether you need to create a register and tick it according to sensitivity list or you want to create a port/pin assignment

南巷近海 2024-10-31 06:01:01

基本上 reg 用于存储值。例如,如果您想要一个计数器(它将计数,因此每个计数都会有一些值),我们将使用 reg。
另一方面,如果我们只有一个带有 2 个值 0 和 1 的普通信号,我们会将其声明为 Wire。Wire 不能保存值。因此,为 Wire 分配值会导致问题......

basically reg is used to store values.For example if you want a counter(which will count and thus will have some value for each count),we will use a reg.
On the other hand,if we just have a plain signal with 2 values 0 and 1,we will declare it as wire.Wire can't hold values.So assigning values to wire leads to problems....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文