我只是想用 VHDL 制作一个简单的二进制补码设备,但它抛出了这个非常烦人的错误,我不确定我做错了什么。可能是一些非常愚蠢的事情......错误是
“错误 (10327):twocompliment.vhd(21) 处的 VHDL 错误:无法确定运算符“nand”的定义 -- 找到 0 个可能的定义”
代码是
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity twoscompliment is
generic
(
Nbits : positive := 8
);
port
(
--Inputs
A : in std_logic_vector (Nbits-1 downto 0);
--Outputs
Y : out std_logic_vector (Nbits downto 0)
);
end twoscompliment;
architecture twoscompliment_v1 of twoscompliment is
begin
Y <= std_logic_vector(unsigned(A NAND '1') + '1');
end twoscompliment_v1;
任何帮助都是极好的!
在我看来,你试图否定输入的数字......也许我错过了一些重要的东西,但其他答案给出了一种解决方案,该解决方案在实现目标的同时,似乎比他们需要的更加混乱。
除非丑陋的转换,有什么问题
y <= std_logic_vector(-signed(resize(unsigned(A)), y'length));
当然,我认为如果 A 和 Y 应该表示有符号数(或无符号数),那么它们应该表示为这样:
library ieee;
use ieee.numeric_std.all;
entity twoscomplement is
generic
(
Nbits : positive := 8
);
port
(
A : in unsigned (Nbits-1 downto 0);
Y : out signed (Nbits downto 0)
);
end entity twoscomplement;
architecture a1 of twoscomplement is
begin
Y <= -signed(resize(A, Y'length));
end architecture;
让我们检查一下结果:
entity test_twoscomplement is
end entity;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
architecture test of test_twoscomplement is
signal A : unsigned (7 downto 0);
signal Y : signed(8 downto 0);
begin
dut : entity work.twoscomplement port map (A => A, Y=>Y);
process
begin
for i in 0 to 255 loop
A <= to_unsigned(i, A'length);
wait for 1 ns;
assert to_integer(Y) = -i severity error;
end loop;
report "tests done";
wait;
end process;
end architecture;
使用 GHDL 运行:
$ ghdl -a twoscomp.vhd
$ ghdl --elab-run test_twoscomplement
twoscomp.vhd:40:8:@256ns:(report note): tests done
Success!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)