Thursday, 16 April 2015

Pass unpack array between two modules

module module1();
  bit dyn_ary[11];
  initial begin
    foreach (dyn_ary[i]) begin
      dyn_ary[i] = $urandom_range(10, 12323);
    end
 
    #40;
    foreach (dyn_ary[i]) begin
      $display ($time,,"module1 : dyn_ary[%0d]=%0h", i, dyn_ary[i]);
    end
  end
endmodule : module1


module module2 (input bit dyn_array[11]);
  initial begin
    #100;
    foreach (dyn_array[i]) begin
      $display($time,,"module2 : dyn_array[%0d]=%0h", i, dyn_array[i]);
    end
  end
endmodule : module2
 

module top_module();
  module1 M1 ();
  module2 M2 (.dyn_array(M1.dyn_ary));
endmodule : top_module


Output:
 40 module1 : dyn_ary[0]=0
 40 module1 : dyn_ary[1]=0
 40 module1 : dyn_ary[2]=1
 40 module1 : dyn_ary[3]=0
 40 module1 : dyn_ary[4]=1
 40 module1 : dyn_ary[5]=1
 40 module1 : dyn_ary[6]=0
 40 module1 : dyn_ary[7]=1
 40 module1 : dyn_ary[8]=0
 40 module1 : dyn_ary[9]=1
 40 module1 : dyn_ary[10]=1
100 module2 : dyn_array[0]=0
100 module2 : dyn_array[1]=0
100 module2 : dyn_array[2]=1
100 module2 : dyn_array[3]=0
100 module2 : dyn_array[4]=1
100 module2 : dyn_array[5]=1
100 module2 : dyn_array[6]=0
100 module2 : dyn_array[7]=1
100 module2 : dyn_array[8]=0
100 module2 : dyn_array[9]=1
100 module2 : dyn_array[10]=1

No comments:

Post a Comment