# Need to Use Variable in Assertions ## Delay

**URL:** <https://verificationacademy.com/forums/t/need-to-use-variable-in-assertions-delay/28779>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [August 30, 2013, 7:27pm UTC](https://verificationacademy.com/forums/t/need-to-use-variable-in-assertions-delay/28779 "2013-08-30T19:27:06Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [December 29, 2015, 5:30am UTC](https://verificationacademy.com/forums/t/need-to-use-variable-in-assertions-delay/28779/16 "2015-12-29T05:30:21Z")

</div>

_In reply to [tirumalrao\_m](https://verificationacademy.com/forums/t/need-to-use-variable-in-assertions-delay/28779/15):_

> _In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/need-to-use-variable-in-assertions-delay/28779/15):_  
> I tried above thing but for me g\_i is not fixed It will changes during run.  
> It depends on some other variable in the simulation and that variable changes based on setting.

You missed my main point on the **generate**. The following code generates 16 separate assertions: Thus, the variable can change value. Note that in eh antecedent I have  
$rose(a) && g\_i==delay, thus, if among those 16 assertions, the ones that don’t match the delay create vacuous assertions. The only one that matches and has a successful $rose fire.

```verilog

generate for (genvar g_i=0; g_i<16; g_i++) begin
	 if(g_i ==0)
                ap_delay_gen: assert property ($rose(a) && g_i==delay
      		|=> !b[*g_i] ##1 $rose(b)); // same as |=> $rose(b)
	 else 
	 	ap_delay_gen: assert property ($rose(a) && g_i==delay
      		|=> !b[*g_i-1'b1] ##1 $rose(b));    
        end 
endgenerate 

```

Specifically, you would get

```verilog

 genblock(0)ap_delay_gen: assert property ($rose(a) && 0==delay
      		|=> !b[*0] ##1 $rose(b)); // same as |=> $rose(b)
 genblock(1)ap_delay_gen: assert property ($rose(a) && 1==delay
      		|=> !b[*1-1'b1] ##1 $rose(b)); 
...
genblock(15)ap_delay_gen: assert property ($rose(a) && 15==delay
      		|=> !b[*15-1'b1] ##1 $rose(b)); 

```

Here is the code and simulation results.

 ![](https://verificationacademy.com/forums/uploads/default/original/1X/c2646e1418153404363ef4ad4c23213c6f528072.png)

 ![](https://verificationacademy.com/forums/uploads/default/original/1X/020c6e3558cbf49617fc4083fa5cd224b80c9e0e.png)

[Code used for simulation](http://SystemVerilog.us/m_rose.sv)

It looks like I could have done this instead, I don’t need the 0 case in this case. :

```verilog

generate for (genvar g_i=1; g_i<16; g_i++) begin
	 ap_delay_gen: assert property ($rose(a) && g_i==delay
      		|=> !b[*g_i-1'b1] ##1 $rose(b));    
        end 
endgenerate 

```

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)

- SystemVerilog Assertions Handbook 4th Edition, 2016 ISBN 978-1518681448

---

_[View the full topic](https://verificationacademy.com/forums/t/need-to-use-variable-in-assertions-delay/28779)._
