【发布时间】:2016-10-11 02:45:51
【问题描述】:
我有以下 MWE:
module test(
input wire clock,
input wire start
);
reg [7:0] x = 8'b10101010;
reg processing = 0;
wire [7:0] x_wire0 = x;
wire [7:0] x_wire1 = {4'hf, x};
wire [11:0] x_wire2 = {4'hf, x};
always @(posedge clock) begin
if (start & ~processing) begin
x = 8'h0f;
processing = 1;
end
$display("---> x=%h x_wire0=%h x_wire1=%h x_wire2=%h",
x, x_wire0, x_wire1, x_wire2);
end
endmodule
使用测试台
module test_test();
reg clock = 0;
reg start = 0;
test test(
.clock(clock),
.start(start)
);
always #5 clock = ~clock;
initial begin
$monitor("%b %b", clock, start);
#20 start = 1;
#20 start = 0;
#200 $finish;
end
endmodule
使用 Icarus Verilog 0.9.7 可以得到输出
0 0
---> x=aa x_wire0=aa x_wire1=aa x_wire2=faa
1 0
0 0
---> x=aa x_wire0=aa x_wire1=aa x_wire2=faa
1 0
0 1
---> x=0f x_wire0=0f x_wire1=aa x_wire2=f0f
1 1
0 1
---> x=0f x_wire0=0f x_wire1=0f x_wire2=f0f
1 1
0 0
...
我想知道为什么 x_wire1 直到下一个时钟滴答才会更新,以及是否有任何规则(经验法则)来避免这种情况。 如果我在显示命令之前使用“#0”,它会被更新。
【问题讨论】:
-
在同一个
always块中存在阻塞分配,它们的 RHS 上有x_wire1。我没有在示例代码中包含该代码以使其最小化。我曾经读过非阻塞赋值和阻塞赋值不应该混在同一个always块中。 -
您不应该将阻塞和非阻塞分配混合到 same 变量。
标签: verilog