【问题标题】:Address of array provided as std_logic_vector以 std_logic_vector 形式提供的数组地址
【发布时间】:2014-08-22 15:37:37
【问题描述】:

我正在尝试构建一个 ROM,它的声明为a : in std_logic_vector(5 downto 0) 用于访问地址。我的问题是我不知道如何使用 std_logic_vector 访问 ROM 数组,我应该使用强制转换为整数还是还能做什么?

我的代码:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
--------------------------------------------------------------------------------
entity imem is
    GENERIC(CONSTANT N : INTEGER := 32);
    port (a : in std_logic_vector(5 downto 0);
         result : out std_logic_vector(N-1 downto 0));
end imem;


architecture behavior of imem is
    signal addres : integer;
    type memory is array (0 to 64) of std_logic_vector(N-1 downto 0) ;
    constant myrom : memory := (
         2 => x"11111111" , --255
         3 => x"11010101" , 
         4 => x"01101000" , 
         6 => x"10011011" , 
         8 => x"01101101" , 
         9 => x"00110111" , 
         others => x"00000000" ) ;

begin 
    addres <= signed(a);
    result <= memory(addres);

end behavior;

使用如图所示的此代码,我收到以下错误:

imem.vhd:25:21: can't match type conversion with type integer  
imem.vhd:25:21: (location of type conversion)
imem.vhd:26:21: conversion not allowed between not closely related types  
imem.vhd:26:21: can't match type conversion with type array type "std_logic_vector"
imem.vhd:26:21: (location of type conversion)
ghdl: compilation error  

【问题讨论】:

    标签: vhdl ghdl


    【解决方案1】:

    假设a 是一个无符号地址值,那么您必须先将其转换为无符号,然后再转换为整数。请注意,result 应该访问 myrom 而不是 memory 类型。然后代码可以是:

    addres <= to_integer(unsigned(a));
    result <= myrom(addres);
    

    您甚至可以跳过中间的addres 信号并执行以下操作:

    result <= myrom(to_integer(unsigned(a)));
    

    memory 类型也比要求的长一个,因为 6 位 a 输入只能覆盖 0 .. 63,而不是 0 .. 64。声明 memory 类型的更好方法是通过对a 使用'length 属性,例如:

    type memory is array (0 to 2 ** a'length - 1) of std_logic_vector(N-1 downto 0);
    

    【讨论】:

    • 使用 VHDL-2008 包 numeric_std_unsigned,这变为: result
    【解决方案2】:

    ghdl 语义默认为严格 -1993,这会影响 Morten 的答案变化

    为:

    type memory is array (0 to 2 ** a'length - 1) of 
            std_logic_vector(N-1 downto 0);
    

    我们得到:

    ghdl -a imem.vhdl
    imem.vhdl:15:29:warning: 通用整数绑定必须是数字文字或属性

    ghdl 的作者 Tristan Gingold 在 2006 年撰写了导致语言变更规范的问题报告,该报告明确允许当时的 (-2002) 实现将带有表达式的范围视为一个当另一个边界是通用整数(文字)时,绑定为可转换为整数范围。 LCS 不允许在符合早期版本标准的实现中进行转换。 Tristan 的 ghdl 严格按照这里的规定使用,默认情况下符合 -1993 并产生错误。

    有两种方法可以处理错误。在分析期间使用 ghdl 的命令行选项指定可以将范围转换为整数类型的标准版本或直接提供范围。

    从 ghdl --help-options 我们看到:

    --std=87/93/00/02/08 选择 vhdl 87/93/00/02/08 标准

    此命令行标志可以在 ghdl -a --std=02 imem.vhdl 中传递。

    范围类型也可以直接声明为:

    type memory is array (natural range 0 to 2 ** a'length - 1) of 
                std_logic_vector(N-1 downto 0);
    

    两种分析类型记忆的方法都有效。

    所有这一切的寓意是 VHDL 是一种紧密类型的语言。

    注意事项


    1. -2008 合规性未在当前版本的 ghdl 中完全实现。)
    2. 历史上一直支持解释标准以支持转换。 LCS 克服了歧义。
    3. 参见 IEEE Std 1076-1993 3.2.1.1 索引约束和离散范围第 2 段和 IEEE Std-1076-2008 5.3.2.2 索引约束和离散范围第 2 段。

    1. Tristan 此后更改了 --std= 选项,消除了 -2000 合规性以及默认标准改为 93c,该标准引入了一组标准放宽以更紧密地匹配 VHDL 工具供应商的行业实践。 ghdl 更新版本的用户可以使用--std=93 来严格遵守标准。该问题最初取决于 DAC 赞助的 VASG(VHDL 分析和标准化小组)在 -1987 年之后不允许发布标准解释。可以肯定地说,没有任何 VHDL 标准的单一实现完全遵循特定版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-04
      • 2016-08-09
      相关资源
      最近更新 更多