这两段代码一个是用了堵塞一个是用了非堵塞,这两个模块有什么区别?
综合后的电路这俩模块有区别吗?
module cntx1
(
input clk,
input rst_n,
output reg[4:0] cnt_out
);
always@(posedge clk)
begin
if( rst_n==0 )
cnt_out <= 5'b0;
else
cnt_out <= cnt_out+1'b1;
end
endmodule
module cntx2
(
input clk,
input rst_n,
output reg[4:0] cnt_out
);
always@(posedge clk)
begin
if( rst_n==0 )
cnt_out = 5'b0;
else
cnt_out = cnt_out+1'b1;
end
endmodule
这俩模块虽然是用了堵塞和非堵塞的赋值,但是在 always@(posedge clk) 模块中没有迭代,而是在时钟的边沿触发。
这俩模块没区别。综合后的电路也会使一样的没区别。
在 always@(posedge clk) 中不建议用 = 堵塞赋值,这会影响一些计算的分析。
一般在 always@(*) 组合逻辑里,一些有迭代计算时可以用 = 堵塞赋值