type long_array is array ( 0 to 3 ) of unsigned ( 8 downto 0 ) ;
type short_array is array ( 0 to 3 ) of unsigned ( 7 downto 0 ) ;
signal x : long_array ;
signal y : short_array ;
I want the lower 8 bits of each cell of array x to be assigned to the matching cells of array y.
I.E copy array x into array y while discarding the MSBs of array x.
This is what I wrote:
Code:
y <= x ( ( x ' range ) ( x ( 0 ) ' high - 1 downto 0 ) ) ;
Modelsim compilation fails with the following message:
Slice range direction (downto) does not match slice prefix direction (to).
That's because you defined both 'long_array' and 'short_array' as types instead of subtypes so you will need a type conversion function to convert from one to the other. So your choices are:
- Create a function that takes as input a 'long_array' and returns a 'short array' and keep the type definitions that you have
- Create a more general type, then make 'long_array' and 'short_array' be subtypes of the more general type. That way you don't need any type conversion function.
Example:
Code:
type array2d is array ( natural range <> ) of unsigned; -- Will need to compile with VHDL-2008
subtype long_array is array2d( 0 to 3 ) ( 8 downto 0 );
subtype short_array is array2d( 0 to 3 ) ( 7 downto 0 );