【发布时间】: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_signed和std_logic_arith库。 -
@mkrieger1 OP 正在尝试使用 bit_vectors 进行算术运算,因此 std_logic_* 库在这里无关紧要。
标签: compiler-errors vhdl quartus