Hello,
I am trying to achieve the following task. A loop generates the following values which are placed in an associative array.
00000000000000000000000000000000
00000000000000000000000000000010
00000000000000000000000000000011
00000000000000000000000000000100
00000000000000000000000000000101
00000000000000000000000000000110
00000000000000000000000000001110
00000000000000000000000000011110
00000000000000000000000000111110
00000000000000000000000001111110
I am trying to get some bits on the right side according to a variable. Sometimes it is 2, other times 4, then 8 maybe.
For example in the last one if I have variable value of 4, I should be able to get 1110. If I have variable value of 2, I should get 10.
What I have done so far:
bit [4:0] stream; // to store five of the sliced bits
int array[string]; //the associative array
string symbol; //its index
logic [31:0] code; // The above data is stored in this register for every iteration. Then discarded and new value stored
//rest of the code here to generate more 'code' i.e. the contents of 'array'
array[symbol] = code; //placed inside array
//a loop to iterate over the contents of the array
{<<{stream}} = code; //extracting right-side five bits from array
//Some logic to put these extracted bits in a new array
$display("Bits are %b", stream); //displaying the extracted bits for each iteration of the loop
This worked fine when I was learning about streaming operators, but I run into errors when I want to dynamically change the width of the extraction. I tried this:
bit stream[];
int array[string];
string symbol;
logic [31:0] code;
//rest of the code here to generate the contents of 'array'
array[symbol] = code;
//a loop to iterate over the contents of the array
stream = {<<{code with [j-:0]}}; //extracting right-side bits from 'code', with variable being 'j'
$display("Bits are %b", stream); //displaying the extracted bits for each iteration of the loop
I get this error: syntax error, unexpected with-then-[, expecting ‘,’ or ‘}’
Then I tried this:
logic stream[];
int array[string];
string symbol;
logic [31:0] code;
//rest of the code here to generate the contents of 'array'
array[symbol] = code;
//a loop to iterate over the contents of the array
stream = new[j]; //a dynamic array produced with each iteration
{<<{stream}} = code;
$display("Bits are %b", stream); //displaying the extracted bits for each iteration of the loop
This gives the error: Node VARREF ‘code’ has no expected width?? Missing Visitor func?
How can I achieve my task?