运算符+;没有函数声明;VHDL中的错误
在这段代码中,我得到了+运算符+;没有函数声明;VHDL中的错误,vhdl,Vhdl,在这段代码中,我得到了+ function func (bv1 : in bit_vector; bv2 : in integer) return bit_vector is variable temp : natural := 2**bv2; variable result : bit_vector(1 to 32); begin report "asd" & natural'image(temp); result <= bv1 + tem
function func (bv1 : in bit_vector; bv2 : in integer) return bit_vector is
variable temp : natural := 2**bv2;
variable result : bit_vector(1 to 32);
begin
report "asd" & natural'image(temp);
result <= bv1 + temp; // this line causes the error
return result;
end func;
函数func(bv1:位_向量中;bv2:整数中)返回位_向量为
可变温度:自然温度:=2**bv2;
可变结果:位_向量(1到32);
开始
报告“asd”和自然图像(temp);
结果这是因为您试图将自然
添加到位向量
中,但由于它们的类型不同,因此无法工作。因此,您必须使用转换器,例如,如其中一个函数中所示。另一种方法是坚持使用所有相同的类型,但这并不总是可能的。这是因为您试图向位向量
添加一个自然
,但这不起作用,因为它们属于不同的类型。因此,您必须使用转换器,例如,如其中一个函数中所示。另一种方法是坚持所有相同的类型,但这并不总是可能的。代码的一些初始问题是VHDL注释标记是--
,而不是
/
,并且赋值给结果
变量必须使用:=
,因为代码的一些初始问题是VHDL注释标记是--
,而不是
/
,并分配给结果
变量必须使用:=
,因为不使用位向量
(或标准逻辑向量
s,真的)
使用ieee.numeric_std库,然后根据所需的向量类型,将信号(或任何信号)声明为有符号
ot无符号
。(当然,您可以使用integer
s及其子类型)不要将位向量
(或者std\u逻辑向量
s)用于任何您想要进行算术运算的对象
使用ieee.numeric_std库,然后根据所需的向量类型,将信号(或任何信号)声明为有符号
ot无符号
。(当然,也可以使用integer
s及其子类型)
library ieee;
use ieee.numeric_bit_unsigned.all;
...
function func (bv1 : in bit_vector; bv2 : in integer) return bit_vector is
variable temp : natural := 2**bv2;
variable result : bit_vector(1 to 32);
begin
report "asd" & natural'image(temp);
result := bv1 + to_bitvector(temp, result'length); -- this line causes the error
return result;
end func;