Given an array of naturals. How can i declare an array of std_logic_vectors which will have a size same as the element of the naturals array.To put it more plainly if i have an array T= (5,20,11,10,6) with 5 elements is it possible to create an array of std_logic_vectors where every vector will have the size shown in T .ie 5 vectors the first (5 downto 0) the second (20 downto 0) the third (11 down to 0)and so on.
-
Sounds like homework. The array T will need to be either a constant or a generic. From there, it is just a matter of indexing T. Default direction for indices based on natural is 0 to integer'high.Jim Lewis– Jim Lewis2015-01-29 17:20:18 +00:00Commented Jan 29, 2015 at 17:20
-
why would you need this?Philippe– Philippe2015-01-29 20:21:23 +00:00Commented Jan 29, 2015 at 20:21
-
1Two weeks ago, there was a similar question, which I answered here: Creating a generic array whose elements have increasing width in vhdl. You can replace the increasing size of vectors to your used defined sizes.Paebbels– Paebbels2015-01-29 22:56:54 +00:00Commented Jan 29, 2015 at 22:56
Add a comment
|
1 Answer
Arrays must have the same type for their elements. When the element type is an unconstrained array like std_logic_vector the bounds must all match too. In the simplest case you can't have different length std_logic_vector arrays contained in another array. Normally one would use the largest size array for all of the elements. With access types it is possible to create pointers to arrays of different lengths but that is only usable in simulation.