How to get a slice of INTEGER type out?

Discussion in 'VHDL' started by walala, Sep 5, 2003.

  1. walala

    walala Guest

    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:


    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, Sep 5, 2003
    1. Advertisements

  2. walala

    MM Guest


    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

    MM, Sep 5, 2003
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.