使用VHDL的4位ALU显示错误:没有运算符“+”(“-”、“*”和“/”的函数声明)
当我使用ghdl编译这段代码时,它会产生错误使用VHDL的4位ALU显示错误:没有运算符“+”(“-”、“*”和“/”的函数声明),vhdl,alu,ghdl,Vhdl,Alu,Ghdl,当我使用ghdl编译这段代码时,它会产生错误 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity alu is generic ( constant N: natural := 1 ); port( a,b : in std_logic_vector(3 downto 0); sel : in std_logic_vector(3 dow
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity alu is
generic ( constant N: natural := 1 );
port( a,b : in std_logic_vector(3 downto 0);
sel : in std_logic_vector(3 downto 0);
y : out std_logic_vector(3 downto 0);
x: out std_logic_vector(7 downto 0);
cout : out std_logic);
end alu;
architecture behavioral of alu is
signal rslt : std_logic_vector(3 downto 0);
signal tmp : std_logic_vector(4 downto 0);
begin
process(a,b,sel)
begin
case sel is
when "0000"=>
rslt<= a + b; -- Line 33
when "0001"=>
rslt<= a - b; -- Line 35
when "0010"=>
x<= (unsigned(a)) * (unsigned(b)); -- Line 37
when "0011"=>
x<=(unsigned(a)) / (unsigned(b)); -- Line 39
when "0100"=>
rslt<=std_logic_vector(unsigned(a) sll N);
when "0101"=>
rslt<=std_logic_vector(unsigned(a) srl N);
when "0110"=>
rslt<=std_logic_vector(unsigned(a) rol N);
when "0111"=>
rslt<=std_logic_vector(unsigned(a) ror N);
when "1000"=>
rslt<= a and b;
when "1001"=>
rslt<= a or b;
when "1010"=>
rslt<= a xor b;
when "1011"=>
rslt<= a xnor b;
when "1100"=>
rslt<= a nand b;
when "1101"=>
rslt<= a nor b;
when "1110"=>
if (a > b) then
rslt<= "0001";
else
rslt<="0000";
end if;
when "1111"=>
if (a = b)then
rslt<="0001";
else
rslt<="0000";
end if;
when others=>
rslt<= "0000";
end case;
end process;
y<=rslt;
tmp<= ('0' & a) + ('0' & b); -- Line 78
cout<=tmp(4);
end behavioral;
ghdl-a alu.vhdl
alu.vhdl:33:19:错误:没有运算符的函数声明+
alu.vhdl:35:19:错误:没有运算符的函数声明-
alu.vhdl:37:29:错误:没有运算符的函数声明*
alu.vhdl:39:28:错误:没有运算符的函数声明/
alu.vhdl:78:17:错误:没有运算符+的函数声明
使用无符号算术时,如何使这些运算符可用?欢迎使用Stackoverflow。您显然不太熟悉类型化语言。VHDL是一种类型化语言,其中变量、信号、常量的类型为bit、integer、std_逻辑_vector3 downto 0或unsigned3 downto 0。这些类型定义了可以做什么和不能做什么
默认情况下,您不能将两个std_logic_vector3向下添加到0,而得到的结果也是std_logic_vector3向下添加到0。这就是您尝试使用rsltWelcome to StackOverflow所做的。我建议更好地格式化您的错误,并进一步解释您试图实现的目标。不管怎样,看看这一点,因为您似乎在理解VHDL如何支持向量运算方面遇到了问题。2008修订版软件包numeric_std_unsigned提供了对被视为无符号的std_logic_向量值的算术运算,delirium的链接Synopsys std_logic_unsigned和std_logic_arith提供的一组超级功能,两者都不是标准的一部分。还有关于运算符操作数的类型转换,以及分配给std_逻辑_向量的返回值的类型转换。您可以使用类型为unsigned的端口和中间信号来表示二进制数,而无需更改或添加use子句并删除类型转换。它的可能副本似乎是您在不知道它的作用的情况下复制了代码。我这么说是因为你的代码包含了你自己问题的答案。