阻塞赋值:在顺序块中依次执行。
非阻塞赋值:在顺序块里并行执行。
module blocking
(
input wire sys_clk,
input wire sys_rst_n,
input wire [1:0] in,
output reg [1:0] out
);
reg [1:0] in_reg;
always@(posedge sys_clk or negedge sys_rst_n)//异步复位
if(sys_rst_n == 1'b0)
begin
//非阻塞赋值
in_reg <= 2'b0;
out <= 2'b0;
end
else
begin
in_reg <= in;
out <= in_reg;
end
endmodule
阻塞赋值
module blocking
(
input wire sys_clk,
input wire sys_rst_n,
input wire [1:0] in,
output reg [1:0] out
);
reg [1:0] in_reg;
always@(posedge sys_clk or negedge sys_rst_n)//异步复位
if(sys_rst_n == 1'b0)
begin
//阻塞赋值
in_reg = 2'b0;
out = 2'b0;
end
else
begin
in_reg = in;
out = in_reg;
end
endmodule
测试文件
`timescale 1ns/1ns //时间参数,时间尺度 时间精度
module tb_blocking();
reg sys_clk;
reg sys_rst_n;
reg [1:0] in;
wire [1:0] out;
initial
begin
sys_clk = 1'b1;
sys_rst_n = 1'b0;
in <= 2'b0;
#20
sys_rst_n <=1'b1;
end
always #10 sys_clk = ~sys_clk;
always #20 in <= {$random} % 4;
blocking blocking_inst
(
.sys_clk(sys_clk),
.sys_rst_n(sys_rst_n),
.in(in),
. out(out)
);
endmodule
非阻塞赋值RTL视图:两个寄存器,两个延时
阻塞赋值RTL视图:一个寄存器,产生一个延时效果。