to_integer can not have such operands in this contex

Discussion in 'VHDL' started by A. Kong, Oct 10, 2004.

  1. A. Kong

    A. Kong Guest


    Here is the part of code which defines the arhitecture of a fetch unit:
    architecture behavioral of fetch is
    type type_instruction_array is array(0 to 31) of std_logic_vector(31
    downto 0);

    -- local variable used as a PC internally
    variable PC : std_logic_vector(31 downto 0);
    variable iaddr : integer := 0;
    variable imem : type_instruction_array;


    In the process i want to convert the PC to an integer

    I have tried the following statements:

    iaddr := to_integer(PC);
    iaddr := to_integer( To_bitvector(PC));
    iaddr := to_integer(unsigned(PC));

    I got this error messages:

    to_integer can
    not have such operands in this context.

    Well, I am not sure what is wrong here. I was following 4.2.25 of VHDL
    Faq1. Is my understanding wrong?

    A. Kong, Oct 10, 2004
    1. Advertisements

  2. If I'm not mistaken, integer in VHDL is defined as a 32 bit signed number.
    You cannot take a 32 bit vector, convert it to unsigned, and then place it
    within an integer. It won't fit within the range. to_integer uses either
    signed or unsigned vectors, so I'd expect the first two examples you gave
    to give a different error message, though that will probably depend on your


    Pieter Hulshoff
    Pieter Hulshoff, Oct 10, 2004
    1. Advertisements

  3. A. Kong

    Moti Cohen Guest

    I'm not sure that the "to_integer" function can be used in order to
    convert std_logic_vector to integer. If I remember correctly it can
    only be used for signed/unsigned data input.
    I usually uses the "conv_integer" conversion from the
    STD_LOGIC_UNSIGNED pacakge for peforming such operations
    (std_logic_vector -> integer). but if it is a problem you can first
    convert the std to unsigned and then to integer.

    p.s. - also check that u declared the required ieee pacakge.

    I hope that it is helpful...
    Moti Cohen, Oct 10, 2004
  4. A. Kong

    Alan Fitch Guest

    The last one

    looks OK. Have you said

    library IEEE;
    use IEEE.Numeric_Std.all;

    in front of your entity or architecture?



    Alan Fitch

    DOULOS - Developing Design Know-how
    VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project

    Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24
    1AW, UK
    Tel: +44 (0)1425 471223 mail:

    Fax: +44 (0)1425 471573 Web:

    The contents of this message may contain personal views which are not
    views of Doulos Ltd., unless specifically stated.
    Alan Fitch, Oct 11, 2004
    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.