Verilog开发中阻塞“=”和非阻塞“<=”的区别

module top_module ();
reg clk=0;
reg rstn;
always #5 clk = ~clk; // Create clock with period=10
initial `probe_start; // Start the timing diagram

`probe(clk);        // Probe signal "clk"

// A testbench
reg  in=0;
wire out1;
wire r1;
wire out2;
wire r2;
initial begin
	#10 in <= 1;
	#10 in <= 0;
	#20 in <= 1;
	#20 in <= 0;
	$display ("Hello world! The current time is (%0d ps)", $time);
	#50 $finish;            // Quit the simulation
end

func inst1 ( 
    .clk(clk),
    .rstn(rstn),
    .in(in),
    .r1(r1),
    .out1(out1),
    .r2(r2),
    .out2(out2));   // Sub-modules work too.

endmodule

module func(input clk,input rstn,input in,output reg r1,output reg r2,output reg out1,output reg out2);

always@(posedge clk)
begin
    if (in == 1'b1)begin 
        r1 = 1'b1; 
    end 
    else begin
        r1 = 1'b0;
    end
    if (r1 == 1'b1) begin
        out1 = 1'b1;   
    end 
    else begin
        out1=1'b0;  
    end
end

always@(posedge clk) begin 
    if (in == 1'b1)
        r2 <= 1'b1;
    else
        r2 <= 1'b0;
    
    if (r2 == 1'b1)  
        out2<= 1'b1;
    else 
        out2<= 1'b0;  
    end


`probe(in);	// Sub-modules can also have `probe()
`probe(r1);
`probe(out1);
`probe(r2);
`probe(out2);

endmodule
上述代码的仿真波形如下图所示:
在这里插入图片描述
非阻塞(Non_Blocking)赋值(<=),块结束后才完成赋值操作,值并不是立刻就改变的。

阻塞(Blocking)赋值方式( = ),值在赋值语句执行完后立刻就改变的。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值