Associative array of queue

hello everyone,
i have tried to implement associative array of queue,but its throwing simulation error like Illegal assignment to type ‘bit[31:0]$’ from type 'reg signed

code:


class associative;
  bit [31:0]associative_arr[*][$];
  int index;

  task run();
    for(int i=0;i<10;i++) begin
      index=$urandom_range(0,10);
      associative_arr[index]=$random;
      $display("index=%0d\t,associative_array=%0h",index,associative_arr[index]);
    end
  endtask
endclass

module top();
  associative a;

  initial begin
    a=new();
    a.run();
  end
endmodule

thankyou

In reply to Abhisek Sarkar:

As the error message states, the statement:


associative_arr[index]=$random;

is wrong. You are trying to assign a random number to a queue. You need to treat associative_array[index] as a queue.


class associative;
  bit [31:0]associative_arr[int][$];
  int index;
 
  task run();
    for(int i=0;i<10;i++) begin
      index=$urandom_range(0,10);
      associative_arr[index].push_front($urandom);
      $display("index=%0d\t,associative_array=%0p",index,associative_arr[index]);
    end
  endtask
endclass
 
module top();
  associative a;
 
  initial begin
    a=new();
    a.run();
  end
endmodule

In reply to cgales:

Also note that

  • you should be using $urandom instead of $random to take advantage of SystemVerilog’s random stability and seeding functionality.
  • Associative arrays should have a declared index type and not use a wildcard index. This let you use a number of other SystemVerilog features like foreach loops.

In reply to cgales:

thank you sir.

In reply to cgales:

one more thing how to print the contents inside the associative array of queue ?
if i am using %P in not getting the value.

In reply to Abhisek Sarkar:

The example I posted should work. If it doesn’t, you have a tool issue and need to contact your tool vendor for additional support.