Change Array Length

Hello everyone,

According to the data length code, I want to select my temporary array slice.

For example,

bit [511:0] tmp_array;

When data length = 1
tmp_array[7:0] = data
When data length = 2
tmp_array[15:0] = data

I used the following syntax
tmp_array[data_len_code*8-1:0] = data;

However it gives the following error

“Illegal range in array slice”

How can I select the desired slice of the tmp_array?

Thanks,
Deniz.

In reply to Ankelih:

Verilog does not allow operands with dynamically sized widths. You can create a bitwise mask to do this

tmp_array = data & (512'b1 << data_len_code*8) - 1

In reply to dave_59:

Thanks Dave,

It worked.