将变量传递给VHDL中的过程

时间:2011-02-02 12:17:18

标签: vhdl hdl

我有以下简单程序添加两个数字:

  procedure add_elements
  (
    x : in  std_logic_vector(31 downto 0);
    y : in  std_logic_vector(31 downto 0);   
    r : out std_logic_vector(31 downto 0)
  )
  is

  begin

   r := a + b;

  end;

我想在一个看起来如下的过程中使用这个过程:

  test: process (....)
    variable inp1 : std_logic_vector(31 downto 0);
    variable inp2 : std_logic_vector(31 downto 0);
    variable res : std_logic_vector(31 downto 0);
  begin

    ...
    inp1  := some_value_a;
    inp2  := some_value_b;
    add_elements(inp1, inp2, res);
    ...
  end

然而,在尝试编译时,Modelsim告诉我     子程序“add_elements”

没有可行的条目

任何人都知道这里出了什么问题,签名有问题 add_elements过程?

非常感谢!

3 个答案:

答案 0 :(得分:3)

我想你会想要这样的设置(我注意到了一些拼写错误)。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

我将在这里强制说明您可能希望避免使用std_logic_unsigned并转而使用numeric_std ...继续...继续... 这里没什么有趣的:

entity top is
    port (
    clk : in std_logic;
    x : in std_logic_vector(31 downto 0);
    y : in std_logic_vector(31 downto 0)
    );
end top;

在架构中,我们声明了该过程。我觉得你有一个错字。 (x和y vs a和b)。

architecture top_arch of top is
 procedure add_elements
  (
    x : in  std_logic_vector(31 downto 0);
    y : in  std_logic_vector(31 downto 0);   
    r : out std_logic_vector(31 downto 0)
  )
  is
  begin
   r := x + y;
  end;

begin

现在实际过程:

  test: process (clk)
    variable inp1 : std_logic_vector(31 downto 0);
    variable inp2 : std_logic_vector(31 downto 0);
    variable res : std_logic_vector(31 downto 0);
  begin
    inp1  := x;
    inp2  := y;
    add_elements(inp1, inp2, res);
  end process;
end architecture top_arch;

就是这样。我认为你非常接近,可能错过了一个图书馆和/或有一些错别字。

编辑:我还应该提一下,如果您想重新使用,可以(并且可能应该)将该过程放在单独的包中。然后,您需要使用“use”语句包含该包。

答案 1 :(得分:3)

为什么需要一个程序来添加两个数字?你为什么不立即添加它们?

- 请注意,我假设std_logic_vectors代表数字.--

我建议先将std_logic_vectors转换为无符号或签名(use ieee.numeric_std.all)并使用“+”运算符。你永远不应该use ieee.std_logic_unsigned.all,它只会给你带来麻烦。

答案 2 :(得分:1)

实际上,问题在于“+”的签名。在标准VHDL中,没有使用std_logic_vector定义算术。

正如其他人几乎所建议的那样,请考虑改为使用unsigned中的signedIEEE.numeric_std

为了完整起见,似乎VHDL-2008添加了标准包来对std_logic_vector进行算术运算。但是,与非标准包一样,数字解释(有符号或无符号)取决于使用的包。我不喜欢那样。