geekite

verilog语法执行的顺序问题

0
阅读(2523)
always @ (negedge clk or negedge rst_n)

 if(!rst_n) 

      begin 

       out2 <= 1'b0;
      cnt <= 2'd0;
      end 
    else begin 
       cnt <= cnt + 1'b1;
          if(cnt == 2'd1) out2 <= ~out2;

              else if(cnt == 2'd2)   

                  begin 

                  cnt <= 2'd0;
                  out2 <= ~out2;
                  end 

               end 

比如在一开始复位时,out2 <= 1'b0;在第一个下降沿来时,cnt加1,而下面的语句就不会执行,等到第二个下降沿来时,cnt为2,此时if(cnt == 2'd1) out2 <= ~out2就会执行了,而下面的语句依然不会执行,等到第三个下降沿来时才会执行;