//测试目的:测试在dff中使用posedge clk 触,且使用=号和<=看能不能实现非阻塞和阻塞,阻塞和非阻塞赋值是由什么决定的。 试验1:
module dfftest(clk,ffinput,ffoutput); input ffinput,clk; output ffoutput;
reg ff1,ff2,ff3,ffoutput;//中间的几个dff always @(posedge clk) begin
ffoutput=ff3; ff3=ff2; ff2=ff1; ff1=ffinput;
end endmodule 通过试验测试,能够实现dff的级联。虽然在程序中使用了表示阻塞赋值的=号,由于posedge使得实现了非阻塞式赋值。
当然使用下面的标准写法也是没有问题的。 ffoutput<=ff3; ff3<=ff2; ff2<=ff1; ff1<=ffinput;
试验2:
module dfftest(clk,ffinput,ffoutput); input ffinput,clk; output ffoutput;
wire ff1,ff2,ff3,ffoutput;//中间的几个dff
assign ffoutput=ff3; assign ff3=ff2; assign ff2=ff1; assign ff1=ffinput;
endmodule
使用上面的程序是典型的非阻塞式的写法,注意本来想将写成这样: Reg ff1,ff2,ff3,ffoutput;//中间的几个dff
Ffoutput<=ff3; ff3<=ff2; ff2<=ff1; ff1<=ffinput; 但是这是不符合语法的,在always外面使用wire赋值,而使用wire赋值就必须用assign语句。而且在always之外不能<=。
试验3: module dfftest(clk,ffinput,ffoutput); input ffinput,clk; output ffoutput;
reg ff1,ff2,ff3,ffoutput;//中间的几个dff
always@(clk) begin ffoutput=ff3; ff3=ff2; ff2=ff1; ff1=ffinput; end endmodule 上面为典型的非阻塞赋值的情形。然而,在下面我们将=号变为<=后,依然是非阻塞的情形。
module dfftest(clk,ffinput,ffoutput); input ffinput,clk; output ffoutput;
reg ff1,ff2,ff3,ffoutput;//中间的几个dff
always@(clk) begin ffoutput<=ff3; ff3<=ff2; ff2<=ff1; ff1<=ffinput; end endmodule 结论:在程序中或者在always中,对reg的
或对wire的赋值的方式有阻塞和非阻塞两种,其区分的方式不是由=和,<=区分的,而是由always的触发条件区分的。而在always中触发条件(有或没有posedge)定了其赋值方式就定了。 |