vhdl中的数值运算
Numeric operation in 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;
您必须使用 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;
我是 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;
您必须使用 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;