Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Functions

 
Thread Tools Search this Thread
Old 09-29-2003, 07:39 PM   #1
Default Functions


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
  Reply With Quote
Old 09-29-2003, 08:05 PM   #2
Mike Treseler
 
Posts: n/a
Default Re: Functions
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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Give you enough string functions in Java web reporting tool freezea Software 0 10-08-2009 09:03 AM
Please explain this virtual functions matter (c++) smokey1401 General Help Related Topics 0 07-11-2008 11:53 PM
c# dynamic functions threading Ahmad MCTS 0 07-10-2008 02:12 PM
piece-wise functions in Tex/HTML lou General Help Related Topics 0 10-07-2006 03:08 AM
programming xxd3033 pioneer remote for universal functions jmaroon DVD Video 0 08-27-2006 03:32 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46