VHDL有三元运算符吗?

时间:2013-04-19 19:48:55

标签: vhdl ternary-operator

我喜欢三元运算符vs if子句的整洁。

vhdl中是否存在此运算符?我的搜索恰恰相反。我还检查了when语句,但它不是运算符,我也希望能够在进程中使用它...

3 个答案:

答案 0 :(得分:12)

没有。它是针对VHDL-2008讨论的,但没有进入。你有几个选择。如果您的工具支持VHDL-2008,则条件赋值现在作为顺序语句支持(它们之前只是并发),因此您可以编写如下内容:

process(clock)
begin
  if rising_edge(clock) then
    q <= '0' when reset else d; -- ie. much like q <= reset? '0':d;
  end if;
end process;

如果你没有2008,只需写一个函数(q <= sel(reset, '0', d))。但是,你必须为你感兴趣的每种类型编写它。

答案 1 :(得分:10)

不是像C / C ++那样的人,但你可以使用:

destination <= signal1 when condition else signal2;

答案 2 :(得分:0)

在我的实用程序包中,我具有这两个功能。对我来说,它们非常方便

  function ternu(cond : boolean; res_true, res_false : unsigned) return unsigned is
  begin
     if cond then return res_true;
     else      return res_false;
     end if;
  end function;

  function terni(cond : boolean; res_true, res_false : integer) return integer is
  begin
     if cond then return res_true;
     else      return res_false;
     end if;
  end function;
相关问题