compiler-errors - 如何在 vhdl 中使用“+”操作?
问题描述
我写了一些代码,其中包含一个执行加法运算的过程。我使用“+”符号,编译器无法识别它。我知道 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
解决方案
这是因为您的代码没有包含任何使用位向量执行算术的包。在 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 的无符号算术。
推荐阅读
- visual-studio-code - 如何在 vscode 代码片段中使用 $ 作为文本?
- javascript - Vue JS - 在触发函数之前检查数组中的所有项目是否都已加载
- docker - 启动 docker 容器时运行命令行
- azure-devops - Azure Devops 管道。Visual Studio Build 或 MSBuild 步骤:无需构建即可清理
- python - 如何对齐多个相似数据的x轴?
- mysql - 基于动态值在mysql中进行透视
- java - Gradle 测试 JVM 的默认选项有哪些
- permissions - 为 /etc/fstab 中挂载的目录设置用户权限
- python - 我能找到符合线性方程的坐标吗?
- c# - Identity Server 4 with policies not working when assign more than one role