Functions

S

Salman Sheikh

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?
 
M

Mike Treseler

Salman said:
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;
 

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

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top