SV tircks and tips for interview

QUERY : What if in top module I declare two variable with same name and pass them as an arguement to some task?????

CODE :

module top;
  class aa;
    task disp(int a,real b);
      $display("INT a is ",a);
      $display("REAL b is ",b);
    endtask

  endclass

  initial begin
    int a=5;
    real a=10;
       aa a1 = new;
    a1.disp(a,a);
  end
endmodule

CONCLUSION :  In  module which ever variable you defined first will go as both first and second arguement for disp. 






QUERY :Say in my class all vars are rand and now I want to randomize only one var how to generate this scenario?????

There are multiple ways you can do this.
  1. In test make rand_mode 0 for whole class object and then make rand_mode 1 for that particular variable. 
  2. Use  object.ranomize() method and pass that var as an arguement to this function.
CODE :
 
class abc;
  rand  int Var;
  rand  int MIN;
  rand int  sgr;


  constraint va_c  {Var < 50; Var > 0;}
  constraint slv_c {solve MIN before Var;}
endclass


module scope_4;
  abc obj=new;

  initial begin

   for ( int i = 0;i<10 ;i++)
     if( obj.randomize(Var))
      $display(" Randomization sucsessfull : Var = %0d Min = %0d  sgr = %0d",obj.Var,obj.MIN,obj.sgr);
    else
      $display("Randomization failed");

  #20 $finish;
  end

endmodule 


CONCLUSION :
  • Here which ever vars you pass as arguement to obj.randomize() will only get randomize, rand mode of all other vars will automatically gets OFF.
  • Here one thing to note is that even if you have not declare particular var as rand n if you pass it to obj.randomize() then also it will get randomize.. 




Comments

Popular posts from this blog

'WITH' Operator in SV Coverage

Difference Between m_sequencer and p_sequencer

Cross Auto Bin Max