添加 std_logic_vectors 时出错
我想要一个添加两个 std_logic_vector 的简单模块。但是,当使用代码时 下面的 + 运算符不会合成。
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
entity add_module is
port(
pr_in1 : in std_logic_vector(31 downto 0);
pr_in2 : in std_logic_vector(31 downto 0);
pr_out : out std_logic_vector(31 downto 0)
);
end add_module;
architecture Behavior of add_module is
begin
pr_out <= pr_in1 + pr_in2;
end architecture Behavior;
我从 XST 第 17 行得到的错误消息。
+ 在这种情况下不能有这样的操作数。
我想念图书馆吗?如果可能的话,我不想将输入转换为自然数。
非常感谢
I wanna have a simple module that adds two std_logic_vectors. However, when using the code
below with the + operator it does not synthesize.
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
entity add_module is
port(
pr_in1 : in std_logic_vector(31 downto 0);
pr_in2 : in std_logic_vector(31 downto 0);
pr_out : out std_logic_vector(31 downto 0)
);
end add_module;
architecture Behavior of add_module is
begin
pr_out <= pr_in1 + pr_in2;
end architecture Behavior;
The error message I get from XST
Line 17. + can not have such operands in this context.
Do I miss a library? If possible, I do not wanna convert the inputs into natural numbers.
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您希望编译器如何知道您的 std_logic_vectors 是有符号的还是无符号的?在这两种情况下,加法器的实现并不相同,因此您需要明确告诉编译器您希望它做什么;-)
注意:StackOverflow 中的 VHDL 语法高亮显示很糟糕。将此代码复制/粘贴到您首选的 VHDL 编辑器中,以便更轻松地阅读。
How do you want the compiler to know if your std_logic_vectors are signed or unsigned ? Adder implementation is not the same in these two cases, so you need to explicitly tell the compiler what you want it to do ;-)
Note: VHDL syntax highlighting in StackOverflow is crappy. Copy/paste this code in your preferred VHDL editor to read it more easily.
不要使用
std_logic_arith
- 我已经写过这个(有一定长度:)。使用 numeric_std - 并且在实体端口上使用正确的类型。如果您正在进行算术运算,请使用数字类型(整数或(无)符号向量,视情况而定)。他们会完美地合成。
std_logic_vector 非常有用。
Don't use
std_logic_arith
- I've written about this (at some length :).Do use numeric_std - and do use the right type on your entity ports. If you are doing arithmetic, use numerical types (either integers, or (un)signed vectors, as appropriate). They'll synthesise perfectly well.
std_logic_vector
s are good for@Aurelien 使用 numeric_std 的好建议。
请记住,将两个 32 位值相加可能会得到一个 33 位值,并决定您要如何处理溢出。
Good advice from @Aurelien to use numeric_std.
Bear in mind that adding two 32 bit values can result in a 33 bit value and decide how you want to handle the overflow.
您不能仅使用 std_logic_vector 进行算术运算。您必须将 std_logic_vector 转换为有符号/无符号(取决于您的代码要求)(请参见下面的 1),或者将它们转换为整数(请参见下面的 2)
这些只是示例。您可以根据您的要求更改它们。
You cannot do an arithmetic operation with just std_logic_vector. Either you have to convert the std_logic_vector to signed/unsigned (depending on your code requirements) (see 1 below) or else convert them to integers (see 2 below)
These are just examples. You can change them based on your requirements.
解决此错误的简单方法是:
添加unsign库,
之后您的代码开始工作。
使用
The easy way to solve this error is:
Add library of unsign,
After that your code starts to work.
Use