禁用不以特定值执行的语句
Disable statement not executing at a particular value
我已经为计数器编写了代码,并且正在执行禁用语句。计数器必须计算特定值并在达到该值后退出块。
代码如下:
module counter(
);
parameter number_of_count = 37;
reg clk;
integer count;
initial
begin
count = 5;
clk = 1'b0;
forever #10 clk = ~clk;
end
always @(posedge clk)
begin: this_block
count = count + 1;
$display ($time, " The present count is %d", count);
repeat (number_of_count == count)
begin
count = 5;
disable this_block;
end
end
endmodule
我不确定我错过了什么。
更简单的方法是使用 while
循环:
module counter;
parameter number_of_count = 37;
reg clk;
integer count;
initial
begin
count = 5;
clk = 1'b0;
forever #10 clk = ~clk;
end
initial begin
while (count < number_of_count) begin
@(posedge clk);
count = count + 1;
$display ($time, " The present count is %d", count);
end
end
endmodule
在您的代码中,名为 this_block
的块在 clk
的每个位置执行。您的 disable
只是禁用块执行的当前实例。因为它是块中的最后一条语句,所以您真的看不到 disable
的任何影响。该块在 clk
的每个姿势都重新启用。这是 disable
的不寻常用法。请参阅 IEEE Std 1800-2017,第 9.6.2 节 禁用语句。
注意:disable
很少使用,我建议不要在这里尝试使用它。
代码如下:
module counter(
);
parameter number_of_count = 37;
reg clk;
integer count;
initial
begin
count = 5;
clk = 1'b0;
forever #10 clk = ~clk;
end
always @(posedge clk)
begin: this_block
count = count + 1;
$display ($time, " The present count is %d", count);
repeat (number_of_count == count)
begin
count = 5;
disable this_block;
end
end
endmodule
我不确定我错过了什么。
更简单的方法是使用 while
循环:
module counter;
parameter number_of_count = 37;
reg clk;
integer count;
initial
begin
count = 5;
clk = 1'b0;
forever #10 clk = ~clk;
end
initial begin
while (count < number_of_count) begin
@(posedge clk);
count = count + 1;
$display ($time, " The present count is %d", count);
end
end
endmodule
在您的代码中,名为 this_block
的块在 clk
的每个位置执行。您的 disable
只是禁用块执行的当前实例。因为它是块中的最后一条语句,所以您真的看不到 disable
的任何影响。该块在 clk
的每个姿势都重新启用。这是 disable
的不寻常用法。请参阅 IEEE Std 1800-2017,第 9.6.2 节 禁用语句。
注意:disable
很少使用,我建议不要在这里尝试使用它。