Negative array index

Status
Not open for further replies.

mahmood.n

Member level 5
Joined
Dec 2, 2011
Messages
85
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,046
What is the purpose of defining an array with negative index?! If I define
Code:
type myArray is (Natural <>) of bit;
Then I can use

Code:
signal myBitArray : myArray( 10 downto 0 )

and use myBitArray(10)...myBitArray(0)

But
Code:
type myArray is (Negative <>) of bit;
Means
Code:
signal myBitArray : myArray( -10 to 0 )
So what does myBitArray(-10) means?
 

its just a way of indexing. In VHDL you can use any type you want as the index, so if you wanted, you could to this:

Code:
type my_ar_t is array( character range <> ) of integer;

signal my_ar : my_ar_t('n' to 'y');

my_ar('r') <= 10;
 
You would need a purpose for a negative index. This currently is used for fixed point numbers in VHDL 2008. negative indicies represent fractions. x(-1) represents 0.5, x(-2) is 0.25, etc...

In other languages, negative values can be used to represent samples before a triggered event.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…