我正在尝试使用 2 位加法器作为组件创建一个 16 位加法器(它们本身使用 1 位加法器作为组件)。但是,我的代码不能在 Quartus II 中编译。有人能帮助我吗?非常感谢!
我的项目由 3 个文件组成:bit_adder.vhd、add2.vhd 和 add16.vhd。错误发生在 add16.vhd 中:
--- bit_adder.vhd
-- description of 1 bit adder
LIBRARY IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity BIT_ADDER is
port( a, b, cin : in STD_LOGIC;
sum, cout : out STD_LOGIC );
end BIT_ADDER;
architecture BHV of BIT_ADDER is
begin
sum <= (not a and not b and cin) or
(not a and b and not cin) or
(a and not b and not cin) or
(a and b and cin);
cout <= (not a and b and cin) or
(a and not b and cin) or
(a and b and not cin) or
(a and b and cin);
end BHV;
-- 下面是 add2.vhd,一个 2 位加法器。使用两个 1 位加法器将两个 2 位数字相加
LIBRARY IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity add2 is
port( a, b : in STD_LOGIC_VECTOR(1 downto 0);
ans : out STD_LOGIC_VECTOR(1 downto 0);
cout : out STD_LOGIC );
end add2;
architecture STRUCTURE of add2 is
-- Component: two 1-bit adders
component BIT_ADDER
port( a, b, cin : in STD_LOGIC;
sum, cout : out STD_LOGIC );
end component;
signal c0, c1 : STD_LOGIC;
begin
c0 <= '0';
b_adder0: BIT_ADDER port map (a(0), b(0), c0, ans(0), c1);
b_adder1: BIT_ADDER port map (a(1), b(1), c1, ans(1), cout);
END STRUCTURE;
-- add16.vhd -- 设置为顶级实体
LIBRARY IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity add16 is
port (a, b : in std_logic_vector(15 downto 0);
sum1 : out std_logic_vector(15 downto 0);
cout : out std_logic_VECTOR(1 downto 0)); --_vector);
end add16;
architecture arch16 of add16 is
component BIT_ADDER
port( a, b, cin : in STD_LOGIC;
sum, cout : out STD_LOGIC );
end component;
component add2
port (a, b : in STD_LOGIC_VECTOR(1 downto 0);
ans : out STD_LOGIC_VECTOR(1 downto 0);
cout : out STD_LOGIC );
end component;
signal c0, c1, c2, c3, c4, c5, c6, c7 : std_LOGIC_VECTOR(1 downto 0);
begin
c0 <='00'; --Error (10500): VHDL syntax error at add16.vhd(26) near text "'"; expecting "(", or an identifier, or unary operator
D_adder0: add2 port map (a(0), b(0), c0, sum1(0), c1);
D_adder1: add2 port map (a(1), b(1), c0, sum1(1), c2);
D_adder2: add2 port map (a(2), b(2), c0, sum1(2), c3);
D_adder3: add2 port map (a(3), b(3), c0, sum1(3), c4);
D_adder4: add2 port map (a(4), b(4), c0, sum1(4), c5);
D_adder5: add2 port map (a(5), b(5), c0, sum1(5), c6);
D_adder6: add2 port map (a(6), b(6), c0, sum1(6), c7);
D_adder7: add2 port map (a(7), b(7), c0, sum1(7), cout);
end arch16;