vhdl 分配无约束 std_logic_vector - lsb 到 msb 或 msb downto lsb

vhdl assign unconstraint std_logic_vector - lsb to msb or msb downto lsb

我想分配一个 std_logic_vector 而不给出界限。像这样:

constant xy: std_logic_vector := "100111";

当我想访问单个位时:

xy(0), xy(1)...xy(5)

我得到

1, 0, 0, 1, 1, 1

这是一样的,就像我分配向量时一样 std_logic_vector(0 到 5).

这种行为是否标准化,分配一个不受约束的向量被解释为 std_logic_vector(0 到 x) 而不是 std_logic_vector(x downto 0),或者这取决于实现?

我现在在用ghdl,但是想用vivado来综合

简而言之,是的,标准化了。当您声明一个不受约束的数组类型的对象时,您需要提供一个约束来指定索引范围(以便编译器可以分配所需的内存,等等)。有几种不同的方法可以做到这一点,其中大多数都需要您明确指定阵列限制和方向。

但是,常量有一个例外(仅):约束可以从用于初始化常量的表达式中推断出来。如果您从字符串文字或具有位置关联的聚合(下面的 AB)进行初始化,则 first/left 元素的索引值取自范围声明,方向取自该类型的方向。对于 std_logic_vector,声明为:

SUBTYPE NATURAL is integer range 0 to integer'high;
...
TYPE std_logic_vector IS ARRAY ( NATURAL RANGE <>) OF std_logic;

NATURAL 是升序的,最左边的索引是 0,所以你的 xy 是一样的。 OTOH,如果初始化程序是具有命名关联的聚合(下面的C),那么常量的索引范围只是从聚合中获取。下面的代码应将 A 和 B 显示为 111001,将 C 显示为 100111。

library IEEE;
use IEEE.std_logic_1164.all;

entity TOP is
end entity TOP;

architecture A of TOP is
begin
  process
    constant A : std_logic_vector := "100111";
    constant B : std_logic_vector := ('1', '0', '0', '1', '1', '1');
    constant C : std_logic_vector := 
      (5 => '1', 4 => '0', 3 => '0', 2 => '1', 1 => '1', 0 => '1');
  begin
    report "A is " &
      std_logic'image(A(5)) & std_logic'image(A(4)) & std_logic'image(A(3)) &
      std_logic'image(A(2)) & std_logic'image(A(1)) & std_logic'image(A(0));
    report "B is " &
      std_logic'image(B(5)) & std_logic'image(B(4)) & std_logic'image(B(3)) &
      std_logic'image(B(2)) & std_logic'image(B(1)) & std_logic'image(B(0));
    report "C is " &
      std_logic'image(C(5)) & std_logic'image(C(4)) & std_logic'image(C(3)) &
      std_logic'image(C(2)) & std_logic'image(C(1)) & std_logic'image(C(0));
    wait;
  end process;
end architecture A;

编辑

如下所述,report 语句不显示这些向量的 'natural' 顺序,这是故意的。您会注意到,这意味着分配给 A 的文字值与报告显示的值相反。如果您不喜欢它,请交换报告中的索引,或改用 to_string(仅限 2008 年)。