阻塞赋值与非阻塞赋值实验Verilog

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阻塞赋值

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

发光中请勿扰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值