# Constraint random generation for ISS

**URL:** <https://verificationacademy.com/forums/t/constraint-random-generation-for-iss/35307>\
**Category:** SystemVerilog\
**Tags:** constarint, SystemVerilog\
**Created:** [November 12, 2018, 7:51am UTC](https://verificationacademy.com/forums/t/constraint-random-generation-for-iss/35307 "2018-11-12T07:51:06Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [November 15, 2018, 5:50pm UTC](https://verificationacademy.com/forums/t/constraint-random-generation-for-iss/35307/9 "2018-11-15T17:50:54Z")

</div>

_In reply to [rupeshblr](https://verificationacademy.com/forums/t/constraint-random-generation-for-iss/35307/8):_

Now what you are doing makes more more sense. You are trying to write code that outputs assembly language text that will be compiled in a later step. What you have shown is informal syntax.

You need to understand the format of the assembly code from the the perspective of the compiler and express it in formal [BNF](http://www.garshol.priv.no/download/text/bnf.html) production terms. Only then you can begin to use randsequence to generate random sequences of instructions based on the BNF rules. The LRM has a very simple example of this

```verilog
randsequence( main )
  main : first second gen ;
  first : add | dec ;
  second : pop | push ;
  add : gen("add") ;
  dec : gen("dec") ;
  pop : gen("pop") ;
  push : gen("push") ;
  gen( string s = "done" ) : { $display( s ); } ;
endsequence

```

You can add random repetition and registers to this with

```verilog
randsequence( main )
main : statements;
statements: repeat ($urandom_range(100,1) statement;
statement: first second gen ;
first : add | dec ;
second : pop | push ;
add : gen("add") sReg dReg endline;
dec : gen("dec") dReg endline;
pop : gen("pop\n") ;
push : gen("push\n") ;
sReg : gen($sformatf("[s%0d]",$urandom_range(127,1))) ;
dReg : gen($sformatf("[d%0d]",$urandom_range(16,1))) ;
endline : gen("\n"); 
gen( string s = "done" ) : { $write( s ); } ;
endsequence

```

---

_[View the full topic](https://verificationacademy.com/forums/t/constraint-random-generation-for-iss/35307)._
