verilog行为建模(四):过程赋值

微信公众号获取更多FPGA相关源码:
在这里插入图片描述

1.两类过程赋值

两类过程赋值

  • 阻塞过程赋值执行完成后再执行在顺序块内下一条语句。

  • 非阻塞赋值不阻塞过程流,仿真器读入一条赋值语句并对它进行调度之后,就可以处理下一条赋值语句。

若过程块中的所有赋值都是非阻塞的,赋值按两步进行:

  1. 仿真器计算所有RHS表达式的值,保存结果,并进行调度在时序控制指定时间的赋值。
  2. 在经过相应的延迟后,仿真器通过将保存的值赋给LHS表达式完成赋值。

2.阻塞与非阻塞赋值语句行为差别举例1

module non_block1;
      reg a, b, c, d, e, f;
   initial begin // blocking assignments
      a = #10 1; // time 10
      b = #2   0; // time 12
      c = #4   1; // time 16
   end
   initial begin // non- blocking assignments
      d <= #10 1; // time 10
      e <= #2   0; // time 2
      f <= #4   1; // time 4
   end
   initial begin
      $monitor($ time,," a= %b b= %b c= %b d= %b e= %b f= %b", a, b, c, d, e, f);
     #100 $finish;
   end
endmodule

输出结果:

时刻abcd
0a= xb= xc= xd= x
2a= xb= xc= xd= x
4a= xb= xc= xd= x
10a= 1b= xc= xd= 1
12a= 1b= 0c= xd= 1
16a= 1b= 0c= 1d= 1

3.阻塞与非阻塞赋值语句行为差别举例2

module pipeMult(product, mPlier, mCand, go, clock);
input           go, clock;
input [7:0]     mPlier, mCand;
output [15:0]   product;
reg [15:0] product;
always @(posedge go)
   product = repeat (4) @(posedge clock) mPlier * mCand;
endmodule
module pipeMult(product, mPlier, mCand, go, clock);
input           go, clock;
input [7:0]     mPlier, mCand;
output [15:0]   product;
reg [15:0] product;
always @(posedge go)
   product <= repeat (4) @(posedge clock) mPlier * mCand;
endmodule

举例2仿真波形

4.阻塞与非阻塞赋值语句行为差别举例3

module fsm(cS1, cS0, in, clock);
input in , clock;
output cS1, cS0;
reg cS1, cS0;
always @(posedge clock) begin
   cS1 = in & cS0;   //同步复位
   cS0 = in | cS1;   //cS0 = in
end
endmodule

RTL电路结构

module fsm(cS1, cS0, in, clock);
input in , clock;
output cS1, cS0;
reg cS1, cS0;
always @(posedge clock) begin
   cS1 <= in & cS0;   //同步复位
   cS0 <= in | cS1;     //同步置位
end
endmodule

5.举例4:非阻塞赋值语句中延时在左边和右边的差别

module exchange;
      reg[3:0] a, b;
      initial begin
               a=1; b=4;
          #2 a=3; b=2;
          #20 $finish;
     end
     initial
$monitor($time, "\t%h\t%h", a, b);
      initial begin
            #5 a <=  b;
            #5 b <=  a;
     end
endmodule

输出结果:

timeab
014
232
522
module exchange;
      reg[3:0] a, b;
      initial begin
               a=1; b=4;
          #2 a=3; b=2;
          #20 $finish;
     end
     initial
$monitor($time, "\t%h\t%h", a, b);
      initial begin
            a <=  #5 b;
            b <=  #5 a;
     end
endmodule

输出结果:

timeab
014
232
541

微信公众号获取更多FPGA相关源码:
在这里插入图片描述

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值