0
\$\begingroup\$

i have an output reg called compressed_out.base_size and delta_size are parameters. if the enable[l] = 0, I need the base_size bits in sub_out to be written to compressed_out. if enable[l]=1, only delta_size number of bits from sub_out is to be taken to compressed_out. how can we give correct ranges in the body of if else statement to select bits of compressed_out. my code is not correct, please help me to solve the issue.

wire [base_size - 1:0 ]sub_out[n-2:0];
.
.
for(l=0;l<n-1;l=l+1)
    begin
    if(enable[l]==0)
    compressed_output[(base_size *(l+2)-1)-:base_size] = sub_out[l];

    else
    compressed_output[(base_size - delta_size)*(l+2)-1 -:(base_size - delta_size) ] = sub_out[l][delta_size -1 :0];
    end  
\$\endgroup\$
1
\$\begingroup\$

What the error says: the size/width of the register, which comes from the expression after the -:, must be a constant.

You can not have variable width assignments. How do you want to do that in hardware?
You can use only part(s) of an existing register which means you have to start with a register big enough for the maximum size you think you will need.


If you tell a bit more about what you want to do and the limits we might come up with a solution. Often shift operations << >> can get you a long way.

\$\endgroup\$
  • \$\begingroup\$ hello, i hope my question is more clear now. I want a generalised expression for the range selection of compressed_out. \$\endgroup\$ – Keerthana T Gopi Nov 27 '19 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.