1、实验内容
通过quartus验证阻塞赋值和非阻塞赋值的不同
2、阻塞赋值
module block_noblock(Clk,Rst_n,a,b,c,out);
input Clk;
input Rst_n;
input a,b,c;
output reg [1:0]out;
//out=a+b+c
//d=a+b
//out=d+c
reg [1:0]d;
always @(posedge Clk or negedge Rst_n)
if(!Rst_n)
out = 2'b0;
else begin
d=a+b;
out=d+c;
end
endmodule
得到的RTL图为
将
d=a+b;
out=d+c;
修改为
out=d+c;
d=a+b;
得到的RTL图为
3、非阻塞赋值
module block_noblock(Clk,Rst_n,a,b,c,out);
input Clk;
input Rst_n;
input a,b,c;
output reg [1:0]out;
//out=a+b+c
//d=a+b
//out=d+c
reg [1:0]d;
always @(posedge Clk or negedge Rst_n)
if(!Rst_n)
out <= 2'b0;
else begin
out<=d+c;
d<=a+b;
end
endmodule
得到的RTL图为
将
out<=d+c;
d<=a+b;
修改为
d<=a+b;
out<=d+c;
得到的RTL图不变
为了便于综合,应减少寄存器的使用,应将
out<=d+c;
d<=a+b;
修改为
out<=a+b+c;
得到的RTL图为
4、仿真
testbench文件
`timescale 1ns/1ns
`define clock_period 20
module block_noblock_tb;
reg Clock;
reg Rst_n;
reg a,b,c;
wire [1:0] out;
block_noblock block_noblock0(Clock,
Rst_n,
a,
b,
c,
out
);
initial Clock = 1;
always #(`clock_period/2) Clock = ~Clock;
initial
begin
Rst_n = 1'b0;
a = 0;
b = 0;
c = 0;
#(`clock_period*200+1);
Rst_n = 1'b1;
#(`clock_period*200);
a = 0;b = 0;c = 0;
#(`clock_period*200);
a = 0;b = 0;c = 1;
#(`clock_period*200);
a = 0;b = 1;c = 0;
#(`clock_period*200);
a = 0;b = 1;c = 1;
#(`clock_period*200);
a = 1;b = 0;c = 0;
#(`clock_period*200);
a = 1;b = 0;c = 1;
#(`clock_period*200);
a = 1;b = 1;c = 0;
#(`clock_period*200);
a = 1;b = 1;c = 1;
#(`clock_period*200);
#(`clock_period*200);
$stop;
end
endmodule
非阻塞赋值存在时延
非阻塞赋值与阻塞赋值相关知识点参考以下:Verilog中的阻塞与非阻塞赋值_小王在学FPGA的博客-CSDN博客_verilog阻塞赋值