Verilog自检测试台将不运行?构建一个简单的ALU,这应该是';别这么难

Verilog自检测试台将不运行?构建一个简单的ALU,这应该是';别这么难,verilog,system-verilog,hdl,modelsim,quartus,Verilog,System Verilog,Hdl,Modelsim,Quartus,我的任务是建立一个ALU。然而,我一定不明白测试台应该如何运行。我已经运行了其他简单的测试台 代码编译(使用quartus) 制作一个文本文件并将其转换为“test.tv”文件 打开modelsim并添加文件 当我运行它时,is的y和zero端口出现问题 这是我的代码: module ALU(input [31:0] a,b, input [2:0] f, output reg [31:0] y , output reg zero); always @(*) begin case(f

我的任务是建立一个ALU。然而,我一定不明白测试台应该如何运行。我已经运行了其他简单的测试台

  • 代码编译(使用quartus)
  • 制作一个文本文件并将其转换为“test.tv”文件
  • 打开modelsim并添加文件
  • 当我运行它时,is的
    y
    zero
    端口出现问题
  • 这是我的代码:

    module ALU(input [31:0] a,b,
    input [2:0] f,
    output reg [31:0] y ,
    output reg zero);
    
    always @(*) begin
    
        case(f)
          3'b000: y = a & b;  
          3'b001: y = a | b;  
          3'b010: y = a + b;    
          3'b011: y = 32'b0;    
          3'b100: y = a & ~b;
          3'b101: y = a | ~b;
          3'b110: y = a - b;
          3'b111: y = a < b;
         default: y = 32'b0;
      endcase
    if(y==0)
        zero=1'b1;
    else
        zero=1'b0;
    end 
    endmodule
    
    //*************************************

    module testALU();
     reg clk;
     reg [31:0]a, b, yexpected;
     reg [2:0]f;
     reg [31:0]y; 
     reg zeroexpected;
     reg zero;
     reg[31:0] vectornum, errors;
     reg [100:0] testvectors[10000:0];
    
     ALU dut(a,b,f,yexpected,zeroexpected);
    
    always
    begin
        clk = 1; #5; clk = 0; #5;
    end
    
    initial
    begin
        $readmemb("test.tv", testvectors);
        vectornum = 0; errors = 0;
    end
    
    always @(posedge clk)
    begin
    #1; {a,b,f,yexpected,zeroexpected} = testvectors[vectornum];
    end
    
    always @(negedge clk)
    begin
    if (y !== yexpected) begin
    $display("Error: inputs = %b", {a,b,f});
    $display(" outputs = %b (%b expected)", y, yexpected);
    errors = errors + 1;
    end
    
    vectornum = vectornum + 1;
    if (testvectors[vectornum] === 100'bx) begin
        $display("%d tests completed with %d errors", vectorum, errors);
        $stop;
     end
     end
    endmodule   
    
    错误:

    module ALU(input [31:0] a,b,
    input [2:0] f,
    output reg [31:0] y ,
    output reg zero);
    
    always @(*) begin
    
        case(f)
          3'b000: y = a & b;  
          3'b001: y = a | b;  
          3'b010: y = a + b;    
          3'b011: y = 32'b0;    
          3'b100: y = a & ~b;
          3'b101: y = a | ~b;
          3'b110: y = a - b;
          3'b111: y = a < b;
         default: y = 32'b0;
      endcase
    if(y==0)
        zero=1'b1;
    else
        zero=1'b0;
    end 
    endmodule
    
    **错误:*(vsim-3043)未解析对“vectorum”的引用。 时间:0 ps迭代:0实例:/testALU文件:C:/Users/prest/Desktop/Hardware Design/ALU/testALU.v行:40

    **错误**(可抑制):(vsim-3053)端口“y”的输出或输入输出端口连接非法。 时间:0 ps迭代:0实例:/testALU/dut文件:C:/Users/prest/Desktop/Hardware Design/ALU/testALU.v行:11

    **错误**(可抑制):(vsim-3053)端口“零”的输出或输入输出端口连接非法。 时间:0 ps迭代:0实例:/testALU/dut文件:C:/Users/prest/Desktop/Hardware Design/ALU/testALU.v行:11

    这就是我的“test.tv”文件在二进制文件中的样子

    > 00000000000000000000000000000000_00000000000000000000000000000000_010_00000000000000000000000000000000_1
    > 00000000000000000000000000000000_11111111111111111111111111111111_010_11111111111111111111111111111111_0
    > 00000000000000000000000000000000_01010101010101010101010101010101_010_01010101010101010101010101010101_0
    
    我知道这可能看起来很愚蠢和简单,但我真的在努力学习这一点,显然不明白什么。有人能帮忙吗?

    您有一些错误

    vectorum
    更改为
    vectorum

    更改模块实例连接,以便不会与
    zeroexpected
    YeExpected
    的测试台信号发生冲突

    将连接到模块输出的信号从
    reg
    更改为
    wire

    module testALU();
       reg clk;
       reg [31:0] a, b, yexpected;
       reg [2:0]  f;
       wire [31:0] y; 
       reg        zeroexpected;
       wire        zero;
       reg [31:0] vectornum, errors;
       reg [100:0] testvectors[10000:0];
    
       ALU dut(a,b,f,y,zero);
    
       always
         begin
            clk = 1; #5; clk = 0; #5;
         end
    
       initial
         begin
            $readmemb("test.tv", testvectors);
            vectornum = 0; errors = 0;
         end
    
       always @(posedge clk)
         begin
            #1; {a,b,f,yexpected,zeroexpected} = testvectors[vectornum];
         end
    
       always @(negedge clk)
         begin
            if (y !== yexpected) begin
               $display("Error: inputs = %b", {a,b,f});
               $display(" outputs = %b (%b expected)", y, yexpected);
               errors = errors + 1;
            end
    
            vectornum = vectornum + 1;
            if (testvectors[vectornum] === 100'bx) begin
               $display("%d tests completed with %d errors", vectornum, errors);
               $stop;
            end
         end
    endmodule   
    
    这将修复所有编译错误