【发布时间】:2013-04-13 07:26:40
【问题描述】:
我喜欢三元运算符与 if 子句的简洁性。
这个操作符是否存在于 vhdl 中?我的搜索结果正好相反。我还检查了when语句,但它不是运算符,我也希望能够在进程中使用它...
【问题讨论】:
标签: vhdl ternary-operator
我喜欢三元运算符与 if 子句的简洁性。
这个操作符是否存在于 vhdl 中?我的搜索结果正好相反。我还检查了when语句,但它不是运算符,我也希望能够在进程中使用它...
【问题讨论】:
标签: vhdl ternary-operator
不是您从 C/C++ 中了解的那种,但您可以使用:
destination <= signal1 when condition else signal2;
【讨论】:
没有。它已针对 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))。不过,您必须为您感兴趣的每种类型编写它。
【讨论】:
(cond when x else y) + (cond when z else w) 工作。
在我的实用程序包中,我有这两个功能。对我来说,它们非常方便
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;
【讨论】: