1

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

  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 告诉我 No feasable entries for subprogram "add_elements"

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

非常感谢!

4

3 回答 3

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 与 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”语句来包含这个包。

于 2011-02-02T14:00:53.853 回答
3

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

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

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

于 2011-02-02T19:48:17.770 回答
1

实际上,问题在于“+”的签名。在标准 VHDL 中,没有用std_logic_vector.

正如其他人几乎建议的那样,请考虑使用unsignedor signedfrom IEEE.numeric_std

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

于 2011-02-02T23:31:32.313 回答