簡體   English   中英

如何在測試台上運行verilog代碼?

[英]How do I run the verilog code on a testbench?

我為波紋進位加法器編寫了代碼。 也可以使用Testbench。 如何在我的Verilog代碼上運行此測試平台? 我沒有模擬器。 我正在使用iverilog編譯器。

ripple_carry_adder.v

module half_adder(a,b,sum,carry);
   input a,b;
   output sum,carry;
   assign sum=a^b;
   assign carry=a&b;
endmodule


module full_adder(a,b,cin,sum,cout);
   input a,b,cin;
   output sum,cout;
   wire   t1,t2;
   half_adder h(a,b,t1,t2);
   assign cout=t1&cin;
   assign sum=t1^cin;
   assign cout=t2|cout;
endmodule // full_adder

module ripple_carry_adder(input1,input2,answer);
   input [31:0] input1,input2;
   output [31:0] answer;
   wire [31:0]   carry;
   full_adder f(input1[0],input2[0],1'b0,answer[0],carry[0]);
   genvar            i;
   generate
      for(i=1;i<=31;i=i+1)
        begin : my_mabel
           full_adder f(input1[i],input2[i],carry[i-1],answer[i],carry[i]);
        end
   endgenerate
endmodule

試驗台

module test;

reg [31:0] input1,input2, expected;
wire [31:0] actual;
integer seed;

ripple_carry_adder dut(input1,input2,actual);

initial begin
    seed = 0;
    repeat(10) begin
        input1 = $random(seed);
        input2 = $random(seed);
        expected = input1 + input2;
        #1;
        if(actual!=expected) $display("ERROR: %0d+%0d was %0d expected %0d",
            input1,input2,actual, expected);
        #9;
    end
end

endmodule

采用:

$ iverilog -o ripple ripple_carry_adder.v ripple_carry_adder_tb.v
$ vvp ripple

在終端中編譯和運行代碼。 您可以在測試台上添加一個$monitor ,以便能夠打印出更多的結果,而不僅僅是錯誤。

還有一個名為GTKWave的配套程序,可用於繪制波形。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM