【问题标题】:What is the difference between input and reg in Verilog?Verilog中的input和reg有什么区别?
【发布时间】:2018-08-24 05:58:45
【问题描述】:

我有一个电路,它的真值看起来像这样A =BC+^C[(B and C) or (not C)]

我给你,

output A;
input B, C;
wire w1, w2;

and (w1, B, C);
not (w2, C);
or (A, w1, w2);

我的问题是我们为什么要写输入B,C;我们可以写成 reg B, C; 吗?

到底有什么区别?

【问题讨论】:

标签: verilog hdl


【解决方案1】:

您没有展示完整的示例,但inputs 和outputs 是分层模块声明的一部分。 reg 是与信号关联的数据类型。通常,将您的电路封装在一个模块中,然后在顶层模块中实例化该模块以提供激励并观察输出。

module circuit( output wire A;
                input wire B, C;
  wire w1, w2; // internal wires

  and (w1, B, C);
  not (w2, C);
  or (A, w1, w2);
endmodule
module top;
reg B,C; // these are different signals that get connected to the circuit wires
wire A;
circuit c(A,B,C);
initial begin
   B = 0; C = 0;
   ...
endmodule

【讨论】:

    【解决方案2】:

    比较inputreg 类似于比较键盘和verilog 代码。 input 定义端口的方向。 reg 定义了一种数据类型。

    但是,每个端口都有与之关联的数据类型。输入/输出端口的默认数据类型是wire。所以input Binput wire B 是一样的。

    现在,正确的问题是:wirereg 之间有什么区别wire 是一种数据类型,用于描述模块实例之间的连接。它的主要特点是它应该始终处于连接状态,否则不能保持状态。 reg 可以保持未连接状态。您可以在相应的verilog教程中找到多种用法差异。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-15
      相关资源
      最近更新 更多