【发布时间】:2018-09-10 13:39:39
【问题描述】:
当我使用 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 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:error: 运算符“+”没有函数声明
alu.vhdl:35:19:error: 没有操作符“-”的函数声明
alu.vhdl:37:29:error: 没有操作符“*”的函数声明
alu.vhdl:39:28:error: 运算符“/”没有函数声明
alu.vhdl:78:17:error: no function declarations for operator "+"
在使用无符号算术时,如何使这些运算符可用?
【问题讨论】:
-
欢迎来到 StackOverflow。我建议更好地格式化您的错误并进一步解释您要达到的目标。无论如何,看看这个post,因为您似乎在理解 VHDL 如何支持向量运算方面遇到了问题。
-
-2008 修订包 numeric_std_unsigned 提供对 std_logic_vector 值的算术运算(被视为无符号,由 delirium 的链接 Synopsys std_logic_unsigned 和 std_logic_arith 提供的功能的超集,既不是标准的一部分)。还有对相关运算符的操作数的类型转换以及分配给 std_logic_vector 的返回值的类型转换。您可以使用无符号类型的端口和中间信号来表示二进制数,而无需更改或添加 use 子句并删除类型转换。
-
您似乎在不知道代码的作用的情况下复制了代码。我这么说是因为您的代码包含您自己问题的答案。