Functions

Discussion in 'VHDL' started by Salman Sheikh, Sep 29, 2003.

  1. e
    I am trying to create a function in vhdl like this:


    function gen_s (si, di :std_logic_vector)
    return std_logic_vector is
    begin
    if (si(z_width) = '1') -- line 71
    return (si(z_width-1 downto 0) & '0' ) + di; -- line 72
    else
    return si(z_width-1 downto 0) & '0' - di;
    end if;
    end gen_s;


    It is inside of an architecture and I keep getting errors when
    compiling in modelsim like this:

    # ** Error: C:/dividers/div_uu.vhd(71): near "return": expecting:
    GENERATE THEN
    # ** Error: C:/dividers/div_uu.vhd(72): near "else": expecting: END_

    What is wrong with this code that causes the errors above?
    Salman Sheikh, Sep 29, 2003
    #1
    1. Advertising

  2. Salman Sheikh wrote:

    > I am trying to create a function in vhdl like this:
    >
    >
    > function gen_s (si, di :std_logic_vector)
    > return std_logic_vector is
    > begin
    > if (si(z_width) = '1') -- line 71
    > return (si(z_width-1 downto 0) & '0' ) + di; -- line 72
    > else
    > return si(z_width-1 downto 0) & '0' - di;
    > end if;
    > end gen_s;
    >
    >
    > It is inside of an architecture and I keep getting errors when
    > compiling in modelsim like this:
    >
    > # ** Error: C:/dividers/div_uu.vhd(71): near "return": expecting:
    > GENERATE THEN
    > # ** Error: C:/dividers/div_uu.vhd(72): near "else": expecting: END_
    >
    > What is wrong with this code that causes the errors above?


    It's actually a syntax error -- missing THEN before ELSE.
    Not a very good error message.

    The code below compiled ok for me

    -- Mike Treseler

    ----------------------------------------------
    constant z_width : natural := 8;
    function gen_s (si, di : unsigned)
    return unsigned is
    begin
    if (si(z_width) = '1') -- line 71
    then
    return (si(z_width-1 downto 0) & '0' ) + di; -- line 72
    else
    return si(z_width-1 downto 0) & '0' - di;
    end if;
    end gen_s;
    Mike Treseler, Sep 29, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    11
    Views:
    805
    tshad
    May 27, 2005
  2. Timothy Wong
    Replies:
    3
    Views:
    399
    Timothy Wong
    May 20, 2004
  3. ILLOGIC
    Replies:
    1
    Views:
    349
    Rob Williscroft
    Jun 1, 2004
  4. Xiangliang Meng
    Replies:
    1
    Views:
    1,576
    Victor Bazarov
    Jun 21, 2004
  5. Steven T. Hatton

    Passing member functions to C functions?

    Steven T. Hatton, Oct 4, 2004, in forum: C++
    Replies:
    7
    Views:
    1,303
    David Hilsee
    Oct 7, 2004
Loading...

Share This Page