vhdl中的数字运算

时间:2018-02-19 13:16:02

标签: vhdl

我是vhdl编程语言的新手。我正在尝试使用“+”运算符制作一个完整的加法器,我制作了代码并且我也编译了但是当我模拟它时输出非常奇怪并且不会随着全加器输出变化,我认为错误可能会在矢量长度,但我无法解决它。

    library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;

entity adder is
port (a,b,c : in std_logic;
    s,d : out std_logic);
end entity;

architecture arc_adder of adder is
signal z : std_logic_vector (1 downto 0);
signal w : std_logic_vector (3 downto 0); 
begin 
z <= ('0'&a + ('0'&b));
w <= '0'&z + "00"&c;
s<=w(0);
d<=w(1);

end architecture;

1 个答案:

答案 0 :(得分:1)

您必须使用unsigned来键入“+”运算符。

无符号类型包含在ieee.numeric_std.all

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity adder is
port (a,b,c : in std_logic;
    s,d : out std_logic);
end entity;

architecture arc_adder of adder is
signal z : std_logic_vector (1 downto 0);
signal w : std_logic_vector (3 downto 0); 
begin 
z <= std_logic_vector(unsigned('0'&a) + unsigned('0'&b));
w <= std_logic_vector(unsigned('0'&z) + unsigned("00"&c));
s<=w(0);
d<=w(1);

end architecture;
相关问题