Reputation: 87
I want write an alternative of the if, I have following if statement.
if val1(1)&val1(0) < val2(1)&val2(0) then
r:="10";
else
if val1(1)&val1(0) = val2(1)&val2(0) then
r:="00";
else
r:="01";
end if;
end if;
And I want it to change to following.
s:=((data1(9)&data1(8)) < (data2(9)&data2(8)))?"01":(((data1(9)&data1(8)) = (data2(9)&data2(8)))?"00":"01");
But the compiler gives me following error.
"# Error: COMP96_0015: min: (111, 49): ';' expected."
How can I resolve this? Thanks.
Upvotes: 1
Views: 928
Reputation: 16221
Question: what's the type of val1 and val2?
Here are some improvements:
val1 < val2
val1(1 downto 0) < val2(1 downto 0)
y <= a when (condition) else b;
statementy = cond ? val1 : val2;
you could define a if-then-else functions let's call it ite
:
function ite(cond : boolean; val1 : std_logic_vector; val2 : std_logic_vector)
return std_logic_vector is
begin
if cond then
return val1;
else
return val2;
end if;
end function;
Usage:
s := ite((val1(1 downto 0) < val2(1 downto 0)), "10", -- less
ite((val1(1 downto 0) = val2(1 downto 0)), "00", -- equal
"01")); -- greater
you could define a compare function, let's call it comp
:
function comp(val1 : std_logic_vector; val2 : std_logic_vector)
return std_logic_vector is
begin
if (val1 < val2) then
return "10";
elsif (val1 = val2) then
return "00";
else
return "01";
end if;
end function
Usage:
s := comp(val1(1 downto 0), val2(1 downto 0));
Upvotes: 2