如何修复 "Illegal reference to memory A" 错误

How to fix the "Illegal reference to memory A" error

我创建了一个8位的比较器,我想把它放在testbench中进行仿真,但是我的testbench有编译错误。

这是我的模块:

`include "BCS_RTL_VERILOG.v"
`timescale 1ns/1ns
module eight_bit_comparator(input [0:7] A, [0:7] B, E0, G0, output E8, G8);
wire [0:8] W1;
wire [0:8] W2;
assign W1[0] = E0;
assign W2[0] = G0;
genvar k;
generate
    for(k=0; k<8; k=k+1) begin: BCSgates
    RTL_BCS rtl_bcs(A[k], B[k], W1[k], W2[k], W1[k+1], W2[k+1]);
end
endgenerate
endmodule

这是我的模块测试台,有 6 个错误:

`timescale 1ns/1ns
module comp_eight_tb();
wire E_out, G_out;
reg A[0:7], B[0:7], E_in, G_in;
eight_bit_comparator(A, B, E_in, G_in, E_out, G_out);
initial begin
#25 A[0]=1;
#25 A[1]=1;
#25 A[2]=1;
#25 A[3]=1;
#25 A[4]=1;
#25 A[5]=1;
#25 A[6]=1;
#25 A[7]=1;
#0 B[0]=1;
#0 B[1]=1;
#0 B[2]=1;
#0 B[3]=1;
#0 B[4]=1;
#0 B[5]=1;
#0 B[6]=1;
#0 B[7]=1;
#5 E_in=1;
#0 G_in=1;
#20 $stop;
end
endmodule

错误:

comp_eight_tb.v(5): (vlog-2110) Illegal reference to memory "B".
comp_eight_tb.v(5): (vlog-2110) Illegal reference to net array "#implicit-wire#1".
comp_eight_tb.v(5): (vlog-2110) Illegal reference to memory "B".
comp_eight_tb.v(5): (vlog-2110) Illegal reference to memory "A".
comp_eight_tb.v(5): (vlog-2110) Illegal reference to net array "#implicit-wire#0".
comp_eight_tb.v(5): (vlog-2110) Illegal reference to memory "A".

这些错误是针对测试台中的第 5 行,但我无法识别问题所在。谁能解决这个问题并解释原因?

在testbench中,你应该声明AB左边的位范围。此外,更传统的做法是将 MSB 指定在 LSB 的左侧。由于您没有 post RTL_BCS 模块的代码,我将它的实例注释掉了。这段代码为我编译没有错误:

module eight_bit_comparator (
    input [7:0] A,
    input [7:0] B,
    input E0,
    input G0,
    output E8,
    output G8
);
wire [0:8] W1;
wire [0:8] W2;
assign W1[0] = E0;
assign W2[0] = G0;
/*
genvar k;
generate
    for(k=0; k<8; k=k+1) begin: BCSgates
    RTL_BCS rtl_bcs(A[k], B[k], W1[k], W2[k], W1[k+1], W2[k+1]);
    end
endgenerate
*/
endmodule


`timescale 1ns/1ns
module comp_eight_tb();
wire E_out, G_out;
reg [7:0] A, B;
reg E_in, G_in;

eight_bit_comparator dut (A, B, E_in, G_in, E_out, G_out);

initial begin
    #25 A[0]=1;
    #25 A[1]=1;
    #25 A[2]=1;
    #25 A[3]=1;
    #25 A[4]=1;
    #25 A[5]=1;
    #25 A[6]=1;
    #25 A[7]=1;
    #0 B[0]=1;
    #0 B[1]=1;
    #0 B[2]=1;
    #0 B[3]=1;
    #0 B[4]=1;
    #0 B[5]=1;
    #0 B[6]=1;
    #0 B[7]=1;
    #5 E_in=1;
    #0 G_in=1;
    #20 $stop;
end
endmodule

我通过在测试台中添加 dut 实例名称修复了另一个编译错误。