在QuestaSim中编译VHDL时,我收到一条我不理解的警告:
(vcom-1514)范围选择方向(向下)不能确定聚合索引范围方向(到)。
触发警告的代码类似于具有
signal foo : unsigned(4 downto 0);
在begin
之前的体系结构中,然后在某个进程内部
if foo = (foo'high => '1', foo'high - 1 downto foo'low => '0') then
上面的行将在以下情况触发警告
if foo = (foo'high => '1', foo'low to foo'high - 1 => '0') then
不会,即使foo
的索引方向是downto
而不是to
。
有人知道为什么在这种情况下我应该使用to
而不是downto
进行索引吗?
答案 0 :(得分:3)
汇总
(foo'high => '1', foo'high - 1 downto foo'low => '0')
具有索引范围方向“至”。您的警告是说:不要仅仅因为您包含其中定义为'downto'的数组而想到它的方向是'downto'。
为什么默认方向为“到”?好吧,我们需要考虑此聚合的类型。 (来吧-这是VHDL-它必须具有类型)。
在我的代码中,其类型为unsigned
。为什么?好吧,因为我已将其与类型为unsigned
的过程的输入相关联。在您的代码中,其类型也是unsigned
。为什么?好吧,因为它是=
运算符的右手参数,其左手参数肯定是unsigned
。 =
运算符只有一种可能的版本,它可以测试两个unsigned
。
现在,我们需要查看类型unsigned
的声明方式,当我们这样做时,我们会看到它被声明为索引类型为natural
的不受约束的数组:
type unsigned is array (natural range <>) of std_logic;
类型natural
的左手值为0。因此,这就是为什么聚合的索引范围方向为“至”。
如果执行此代码,则可以看到VHDL如何在聚合上定义索引:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity E is
end entity ;
architecture A of E is
signal foo : unsigned(4 downto 0);
begin
process
procedure display (constant foo : in unsigned) is
begin
report "foo'left= " & integer'image(foo'left);
report "foo'right= " & integer'image(foo'right);
report "foo'high= " & integer'image(foo'high);
report "foo'low= " & integer'image(foo'low);
end procedure;
begin
display((foo'high => '1', foo'high - 1 downto foo'low => '0'));
wait;
end process;
end architecture A;