首页 文章

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

提问于
浏览
3

我想分配一个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进行综合 .

1 回答

  • 3

    简而言之,是的,标准化的 . 声明无约束数组类型的对象时,需要提供约束来指定索引边界(以便编译器可以分配所需的内存,依此类推) . 有几种不同的方法可以做到这一点,其中大多数都需要您明确指定数组限制和方向 .

    但是,常量(仅)有一个例外:约束可以从用于初始化常量的表达式推断出来 . 如果从字符串文字或具有位置关联的聚合(下面的 AB )初始化,那么第一个/左边元素的索引值取自范围声明中类型的最左边元素,并且方向取自那种方向 . 对于 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 语句请注意,这意味着分配给 A 的文字值与报告显示的值相反 . 如果您不喜欢它,请在报告中交换索引,或使用 to_string (仅限2008) .

相关问题