如何在vhdl中使用操作“+”?

How can I use the operation "+" in vhdl?

我写了一些代码,其中包含一个加法程序 operation.I 使用“+”符号,编译器无法识别 it.I 知道 vhdl 不支持这个符号,但是我们的教授有要求我们在我们的 code.Is 中使用它,有什么方法可以正确使用“+”?

我用了所有我知道的库都没有结果。这是我的代码:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
use ieee.std_logic_signed.all;
use ieee.std_logic_arith.all;

package arith_operation is
  constant size: integer :=8;
  constant select_bits: integer :=3;
  procedure add( x,y: in bit_vector(size-1 downto 0);
                 sum: out bit_vector(size-1 downto 0); c_out: out bit );
end arith_operation;

package body arith_operation is
  procedure add
         ( x,y: in bit_vector(size-1 downto 0);
           sum: out bit_vector(size-1 downto 0);
           c_out: out bit) is
  variable s: bit_vector(size downto 0);
  begin
    s:= ("0" & x) + ("0" & y);
    sum:= s(size-1 downto 0);
    c_out:= s(size);
  end procedure add;
end arith_operation;

这是出现的错误:

Error (10327): VHDL error at arith_operation.vhd(22): can't determine definition of operator ""+"" -- found 0 possible definitions

这是因为您的代码没有包含任何使用位向量执行算术运算的包。直到 VHDL 2008,还没有这个包。 VHDL 2008 引入了 numeric_bit_unsigned 以允许使用 bit_vectors 的无符号算术,以及使用位定义无符号和有符号类型的 numeric_bit。 (这与 numeric_std 形成对比,numeric_std 具有使用 std_logic 作为基本元素类型定义的相同类型。

您还遇到了库冲突和非标准库的问题。非标准的 std_logic_arith 应该被删除,因为它与 numierc_std 冲突。 std_logic_unsigned 和 std_logic_signed 都是非标准的,使用 std_logic_vectors 执行算术运算,并且还定义了相同的函数。理想情况下,您不会使用任何一个库,因为它们是非标准 VHDL,但如果您必须使用它们,使用它们的最简单方法是只包含一个或另一个,而不是两个。 (您可以同时使用两者,但是您需要使用带有完整路径的函数)。您可以改为使用 VHDL 2008 中添加的 numeric_std_unsigned 来使用 SLV 进行无符号算术。