Verilog $stop $finish

Stopping and finishing in a simulation


The task $stop is provided to stop during a simulation.
Usage: $stop; (断点)
The $stop task puts the simulation in an interactive mode. The designer can then debug
the design from the interactive mode. The $stop task is used whenever the designer wants
to suspend the simulation and examine the values of signals in the design.


The $finish task terminates the simulation.
Usage: $finish;(结束)
 

参考文件
1:Verilog HDL A Guide to Digital Design and Synthesis, Second Edition  第56页

module DW01_add_tb; // Declare inputs and outputs reg [3:0] A; reg [3:0] B; reg CI; wire [3:0] SUM; wire CO; // Instantiate design under test DW01_add dut( .A(A), .B(B), .CI(CI), .SUM(SUM), .CO(CO) ); // Initialize inputs initial begin A = 4'b0000; B = 4'b0000; CI = 0; end // Adder test case task test_adder; // Test case 1: 0 + 0 with carry-in of 0 A = 4'b0000; B = 4'b0000; CI = 0; #10; if (SUM !== 4'b0000 || CO !== 1'b0) $display("Test failed! 0 + 0 should be 0 with carry-out of 0"); // Test case 2: 7 + 3 with carry-in of 0 A = 4'b0111; B = 4'b0011; CI = 0; #10; if (SUM !== 4'b1010 || CO !== 1'b0) $display("Test failed! 7 + 3 should be 10 with carry-out of 0"); // Test case 3: 5 + 11 with carry-in of 1 A = 4'b0101; B = 4'b1011; CI = 1; #10; if (SUM !== 4'b0001 || CO !== 1'b1) $display("Test failed! 5 + 11 should be 16 with carry-out of 1"); // Test case 4: 15+15 with carry-in of 1 A = 4'b1111; B = 4'b1111; CI = 1; #10; if (SUM !== 4'b1110 || CO !== 1'b1) $display("Overflow!!!"); endtask // Run test cases initial begin test_adder(); $finish; end endmodule // DW01_add_tb If I want to replace the delays, i.e, #10; in this piece of verilog code, by below code: integer cyc; initial cyc=1; always @ (posedge clk) begin cyc <= cyc+1; if(cyc==1)begin in_val1 <=4'd4; end else if (cyc==2) begin if (out_val1 !==8'b1) $stop; in_val <=4'd3; end else if (cyc==3)begin if(out_val1 !== 8'b10)$stop; in_val1 <= 4'd7; end else if(cyc==4) begin $write("ALL Finished \n"); $finish; end end in other words, using pound delay # is not allowed, how should I modify the code?
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值