1

Problem: I have N elements of X bits each, and have them concatenated into 1 vector and now I want to unpack them into a matrix M[N][X] using for loops. For example,

input [N*X-1:0]VECTOR;
integer i;
reg [X-1:0]M[N-1:0];
always@(*) begin
    for(i=0; i<N; i=i+1) begin
        M[i] = VECTOR[(X*(i+1)-1):(X*i)];
    end
end

However, the above code gives me the following error:

Error (10734): Verilog HDL error at FILE.v(line_number): i is not a constant

1 Answer 1

1

A few corrections:

input [N*X-1:0] VECTOR; // move range to the other side
integer i;
reg [X-1:0] M [0:N-1]; // Give proper range with X
always @* begin // always block for comb logic
  for(i=0; i<N; i=i+1) begin // not i=i++
    M[i] = VECTOR[X*i +: X]; // vector slicing
  end
end

Refer to previously answered questions to explain +: vector slicing:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.