Range must be bounded by constant expressions

This will help you avoid accessing elements out of range and solve the issue with the red part of the code.
  • #1
hoheiho
47
0

Homework Statement


Code:
logic [4:0]counter;
logic [WORD_W-1:0] mdr_rite_[COLOR="Red"][counter][/COLOR];  //range must be bounded by constant expressions
logic [WORD_W-OP_W-1:0] mar_rite_[COLOR="red"][COLOR="Red"][counter][/COLOR][/COLOR]; //range must be bounded by constant expressions

always_ff@(posedge clock, negedge n_reset)
  begin
    if (!n_reset)
      begin
      SE <= 0;
      counter <=0;
      end
    else
      if (check)
        if (counter < 10)
            begin
            counter<=counter+1;
            mar_rite_[counter] <= mar_check;
            mdr_rite_[counter] <= mdr_check;
            end
          else
              counter<=counter+1;
            if (mar_rite_[counter]!=mar_check|mdr_rite_[counter]!=mdr_check)
              SE<=SE+1;
    end
endmodule

mar_check, mdr_check and check are the input. mar_rite, mdr_rite and counter are for internal use. And SE is the output.
If check = 1, counter will +1. When counter is 0 to 9, the mar_check and mdr_check will store in the mar_rite_[counter] and mdr_rite_[counter]. If the counter is 10 or above, it will compare the mdr and mar value. If they are not the same, SE+1.
It say the red colour part cannot be this kind of various. So I have to use another way to do this. I have try to use FSM but that is a bit long. Is there any hint for me to fix the errors?

I guess the same problem as http://www.edaboard.com/thread21319.html
But I am not quite understand how it does

Best regard
 
Physics news on Phys.org
  • #2
Homework EquationsN/AThe red part of the code cannot work because you are trying to access elements in an array that are out of range. The range of your array is 0 to 9, but you are trying to access element 10 and beyond. This will cause an error. You should use a different approach such as a Finite State Machine (FSM) to achieve the same result. In the FSM you can define the states of your program, and when certain conditions are met, the program can transition from one state to another. You can also set conditions for when to increment the counter and when to compare the mar and mdr values.
 

What does it mean for a range to be bounded by constant expressions?

When a range is bounded by constant expressions, it means that the values at the beginning and end of the range are fixed and cannot change. These values must be specified as constant expressions, meaning they cannot be variables or calculated values.

Why is it important for a range to be bounded by constant expressions?

Bounding a range by constant expressions ensures that the range remains consistent and does not change unexpectedly. This is important for maintaining accuracy and avoiding errors in scientific experiments and calculations.

Can a range be bounded by non-constant expressions?

No, a range must be bounded by constant expressions. Non-constant expressions, such as variables or calculated values, can change and therefore do not provide a fixed boundary for the range.

What types of ranges need to be bounded by constant expressions?

Any range used in scientific research or calculations should be bounded by constant expressions in order to ensure accuracy and consistency. This includes ranges used in data analysis, statistical analysis, and mathematical models.

How can I determine the appropriate constant expressions to bound a range?

The appropriate constant expressions to bound a range will depend on the specific context and purpose of the range. It is important to carefully consider the values that are needed for the beginning and end of the range and ensure that they are fixed and unchanging.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
10K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
983
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Electrical Engineering
Replies
6
Views
4K
  • Programming and Computer Science
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
Replies
9
Views
2K
Back
Top