Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VHDL中向过程传递变量_Vhdl_Hdl - Fatal编程技术网

在VHDL中向过程传递变量

在VHDL中向过程传递变量,vhdl,hdl,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

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

  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_元素没有可用的条目

谁知道这里出了什么问题,签名有问题吗 添加元素程序的详细信息


非常感谢

我想你会想要这样的设置。我注意到了一些打字错误

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
我将在这里加入一个强制性的注释,您可能希望避免使用std\u logic\u unsigned,转而使用numeric\u 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语句包含该包。

我想您需要这样的设置。我注意到一些输入错误

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
我将在这里加入一个强制性的注释,您可能希望避免使用std\u logic\u unsigned,转而使用numeric\u 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语句包含包。

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

-注意,我假设std_逻辑_向量表示数字-


我建议先使用ieee.numeric\u std.all并使用+运算符将std_logic_向量转换为无符号或有符号。千万不要使用ieee.std\u logic\u unsigned.all,它只会给你带来问题。

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

-注意,我假设std_逻辑_向量表示数字-


我建议先使用ieee.numeric\u std.all并使用+运算符将std_logic_向量转换为无符号或有符号。你不应该使用ieee.std\u logic\u unsigned.all,它只会给你带来问题。

事实上,问题在于+的签名。在标准VHDL中,没有用std_逻辑_向量定义的算法

正如其他人所建议的,请考虑使用IEEE.NICICICSTD代替的未签名或签名。


为了完整性,VHDL-2008似乎增加了标准包,以便在std_逻辑_向量上进行运算。但是,与非标准软件包一样,有符号或无符号的数字解释取决于使用的软件包。我不喜欢那样。

事实上,问题在于+的签名。在标准VHDL中,没有用std_逻辑_向量定义的算法

正如其他人所建议的,请考虑使用IEEE.NICICICSTD代替的未签名或签名。


为了完整性,VHDL-2008似乎增加了标准包,以便在std_逻辑_向量上进行运算。但是,与非标准软件包一样,有符号或无符号的数字解释取决于使用的软件包。我不喜欢这样。

绝对推荐使用ieee.numeric\u std.allA建议使用非标准软件包,即使有警告说明,也不是很好的建议。帮助我们保存VHDL:-我当然认识到使用std_logic_unsigned是不合适的,但为了最直接地回答眼前的问题,我决定不使用OP没有询问的主题来混淆视听。现在的问题是关于过程的使用。这个问题似乎是关于过程的,但从您的回答中可以看出,问题实际上是关于类型的。另一个想法是:不要使用只有一个输出参数的过程,自然的解决方案是使用函数代替。明确建议使用ieee.numeric_std.allA建议使用非标准软件包,即使有警告说明,也不是很好的建议。帮助我们保存VHDL:-我当然认识到使用std_logic_unsigned是不合适的,但为了最直接地回答眼前的问题,我决定不使用OP没有询问的主题来混淆视听。现在的问题是关于过程的使用。这个问题似乎是关于过程的,但从您的回答中可以看出,问题实际上是关于类型的。另一个想法是:与其只使用一个输出参数的过程,自然的解决方案是使用函数。