【问题标题】:How can I use the operation "+" in vhdl? [duplicate]如何在 vhdl 中使用“+”操作? [复制]
【发布时间】:2019-04-29 10:09:45
【问题描述】:

我写了一些代码,其中包含一个执行加法运算的过程。我使用“+”符号,编译器无法识别它。我知道 vhdl 不支持这个符号,但是我们的教授要求我们在我们的代码。有什么方法可以使用“+”而不会出错?

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

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

【问题讨论】:

  • 使用unsigned 类型(来自numeric_std 库)执行添加。不要使用 std_logic_signedstd_logic_arith 库。
  • @mkrieger1 OP 正在尝试使用 bit_vectors 进行算术运算,因此 std_logic_* 库在这里无关紧要。

标签: compiler-errors vhdl quartus


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多