Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何实例化在Verilog中具有reg端口的模块?_Verilog_Instantiation - Fatal编程技术网

如何实例化在Verilog中具有reg端口的模块?

如何实例化在Verilog中具有reg端口的模块?,verilog,instantiation,Verilog,Instantiation,我有一个这种类型的模块: module rgst( input d,... output reg [3:0]); ... endmodule 我想为它编写一个测试台: module rgst_tb( output reg d, ... output reg [3:0]q); rgst uut(.d(d),...,q(q)); ... 问题是,我不能以这种方式在测试台上实例化我的模块,因为q是reg类型 通常,包含测试台代码的模块可以有两种样式之一

我有一个这种类型的模块:

module rgst(
   input d,...
   output reg [3:0]);

...

endmodule
我想为它编写一个测试台:

module rgst_tb(
   output reg d,
   ...
   output reg [3:0]q);
   rgst uut(.d(d),...,q(q));
   ...

问题是,我不能以这种方式在测试台上实例化我的模块,因为
q
reg
类型

通常,包含测试台代码的模块可以有两种样式之一:被测试模块(DUT)在测试台模块(TB)本身中实例化,或者DUT和TB在将它们连接在一起的顶级模块中分别实例化。你只能做一件事,不能同时做两件事;许多不熟悉这门语言的人往往把它们混在一起

+-----------------+         +--------------------------------+
|  module tb      |         | module top                     |
|  +-------------+|         |  +------------+  +------------+|
|  | module dut  ||    or   |  | module tb  |==| module dut ||
|  +-------------+|         |  +------------+  +------------+|
+-----------------+         +--------------------------------+
在第一种类型中,TB模块不需要任何输入或输出,它只需要在本地声明并在本地操作/监控DUT端口的导线/寄存器:

module tb;
   // Declare ports of DUT as locals inside TB
   wire outval;
   reg inval;

   // Instantiate DUT inside TB module
   dut u1(.in(inval), .out(outval));

   // Stimulus and monitor here
   initial begin
     $monitor(outval);
     inval <= ...;
   end
endmodule
模块tb;
//将DUT端口声明为TB内的本地端口
钢丝绳;
无效登记;
//实例化TB模块内的DUT
dut u1(.in(无效),.out(outval));
//刺激和监测在这里
初始开始
$monitor(outval);

inval我以前看到的误解是,人们认为你必须将注册码与注册码连接起来。

它不像一个类型,你必须有匹配的类型

模块的输出端口始终连接到
导线
。(如果您有系统Verilog,则转到
logic

根据经验:

每当使用“始终”*语句为变量赋值时,都需要“reg”。 不幸的是,非常令人困惑:这与合成后是否有寄存器无关!因此,在系统Verilog中引入了“逻辑”类型,消除了“reg”混淆

wire  this_is_a_wire;
reg   this_is_a_reg;
   assign this_is_a_wire = ....
   always (...)
     this_is_a_reg ...

*这也可以是一个永远的梳子

为什么你不能?请提供可复制的示例和错误消息(如果有)。这在SystemVerilog中有效。
wire  this_is_a_wire;
reg   this_is_a_reg;
   assign this_is_a_wire = ....
   always (...)
     this_is_a_reg ...