将模块输出连接到寄存器

Ran*_*lue 4 verilog

我尝试将模块输出连接到寄存器,如下所示:

module test
(
  input rst_n,
  input clk,
  output reg [7:0] count
);
  always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
      count <= 7'h0;
    end else begin
      if(count == 8) begin
        count <= count;
      end else begin
        count <= count + 1'b1;
      end
    end
  end
endmodule

module test_tb;
    reg clk;
    reg rst_n;
    reg [7:0] counter;

    initial begin
        clk = 1'b0;
        rst_n = 1'b0;
        # 10;
        rst_n = 1'b1;
    end
    always begin
        #20 clk <= ~clk;
    end

    test test1 (
        .rst_n(rst_n),
        .clk(clk),
        .count(counter) /* This is the problematic line! */
    );
endmodule
Run Code Online (Sandbox Code Playgroud)

Illegal output or inout port connection for "port 'count'在ModelSim中得到了错误" ".即使错误与我的代码匹配,我也不明白为什么,从根本上说,我无法将模块输出连接到寄存器.

为什么我不能将模块输出连接到Verilog中的寄存器?

too*_*lic 6

您只能reg过程 always块中的值分配值.您无法reg从模块实例中驱动a .这将是一个持续的协助.

使用wire内部test_tb.