How to get a slice of INTEGER type out?

W

walala

Dear all,

I declared:

Variable Temp: INTEGER RANGE -32768 TO 32767;
Signal x: INTEGER RANGE -128 TO 127;
Signal y: INTEGER RANGE -128 TO 127;

I want to do:

Temp=32*x;

y=Temp(15 downto 8);


The compiler has an error message:

Prefix of a slice must be an array...

Which conversion function shall I use in order to get the higher byte
of the 2-word databus?

Thanks a lot,

-Walala
 
M

MM

Walala,

To take a slice from an integer you need to convert it to something like
std_logic_vector or unsigned. Here is an example of such a conversion based
on your code but ignoring negative numbers as I don't want to think about
negatives at the moment:

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;

signal i_x : integer range 0 to 255;
signal u_y : std_logic_vector(7 downto 0);
signal u_temp : unsigned(15 downto 0);

u_temp (12 downto 5) <= to_unsigned(i_x, 8); -- shift by 5 bits is
equivalent to multiplying by 32
u_y <= std_logic_vector(u_temp (15 downto 8)); -- close types can be
converted by casting

/Mikhail
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top