通过两个模块来区别两者。测试平台:Modelsim altera 6.5b
阻塞模块:
module blocking(clk,a,b,c);
input[:] a;
input clk;
output[:] b,c;
reg[:] b,c;
always @(posedge clk)
begin
b=a;
c=b;
$display("blocking:a=%d,b=%d,c=%d.",a,b,c);
end
endmodule
非阻塞模块:
module non_blocking(clk,a,b,c);
input[:] a;
input clk;
output[:] b,c;
reg[:] b,c;
always @(posedge clk)
begin
b<=a;
c<=b;
$display("non_blocking:a=%d,b=%d,c=%d.",a,b,c);
end
endmodule
顶层测试模块:
`timescale 1ns/100ps
`include"blocking.v"
`include"non_blocking.v" module top_blocking;
wire[:] b1,c1,b2,c2;
reg[:] a;
reg clk; initial
begin
clk=;
forever # clk=~clk;
end initial
begin
a='h3;
$display("________________");
# a='d7;
$display("________________");
# a='d15;
$display("________________");
# a='d10;
$display("________________");
# a='d2;
$display("________________");
# $display("________________");
$stop;
end
non_blocking non_bloking1(clk,a,b2,c2);
blocking blocking1(clk,a,b1,c1);
endmodule
运行仿真后结果:
# ________________
# blocking:a= 3,b= 3,c= 3.
# non_blocking:a= 3,b= x,c= x.
# ________________
# blocking:a= 7,b= 7,c= 7.
# non_blocking:a= 7,b= 3,c= x.
# ________________
# blocking:a=15,b=15,c=15.
# non_blocking:a=15,b= 7,c= 3.
# ________________
# blocking:a=10,b=10,c=10.
# non_blocking:a=10,b=15,c= 7.
# ________________
# blocking:a= 2,b= 2,c= 2.
# non_blocking:a= 2,b=10,c=15.
# ________________
可以得出结论:
1,阻塞情况下,display显示的值c=b=a。这说明阻塞赋值是实时更新的。当赋值语句完成后,下一个语句开始,赋值语句的左值就已经发生了变化。
2,非阻塞情况下,display显示的值,b为上一个周期a的值,c为上一个周期b的值。这说明赋值操作是在display语句之后完成的。