I have a function that works with string passed to it. The string should be defined as "a to b" rather than "a downto b". I have the following questions:

  1. How to find out if the string passed is defined in ascending or descending order?
  2. Why do strings not have index 0? The minimum index is 1.
  3. I have string p is 1 to 10, while string q is 10 downto 1, assigning one to the other generates error:

    Fatal: (vsim-3607) Slice range direction (downto) does not match slice prefix direction (to).


  4. How do I assign p to q or q to p in this case?

  • \$\begingroup\$ groups.google.com/forum/m/#!topic/comp.lang.vhdl/riNdx-5NUtY \$\endgroup\$ Oct 1, 2016 at 13:25
  • \$\begingroup\$ Apparently if something is defined as variable str2: string(10 downto 1); and then I use reverse range like str2(1 to 10). The program does not compile. Why, I am not sure. The opposite is also true if the range is defined using "to" and than I try to refer to slice or whole variable index using "downto". \$\endgroup\$
    – quantum231
    Oct 1, 2016 at 14:16
  • \$\begingroup\$ try the library approach \$\endgroup\$ Oct 1, 2016 at 14:22

1 Answer 1

  1. There are a few attributes that can be used to determine the bounds of ranges :

    • T'right and T'left
    • T'low and T'high
    • T'ascending : boolean : indicates a TO=true or DOWNTO=false range.
  2. No idea why VHDL strings usually start at 1

  3. The problem is what means a string defined as (10 downto 1)? Is it some text in a right-to-left language as Arabic? It would make no sense to reverse the order of letters!

  4. If you want to inverse the order, you can use a loop :

    FOR i in p'range LOOP

If it is just because the vector is badly defined, you can write

  • \$\begingroup\$ Re: 3, IEEE Std 1076-2008 8.5 Slice names "The slice is a null slice if the discrete range is a null range." 5.2 Scalar types, 5.2.1 "The range L to R is called an ascending range; if L > R, then the range is a null range. The range L downto R is called a descending range; if L < R, then the range is a null range." \$\endgroup\$
    – user8352
    Oct 1, 2016 at 18:19
  • \$\begingroup\$ Index constraints and discrete ranges "An array constraint of the first form is compatible with the type if, and only if, the constraint defined by each discrete range is compatible with the corresponding index subtype and the array element constraint, if present, is compatible with the element subtype of the type. If any of the discrete ranges defines a null range, any array thus constrained is a null array, having no elements." The OP's string declaration with a null range contains no elements. \$\endgroup\$
    – user8352
    Oct 1, 2016 at 18:27

Your Answer

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

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