4 位超前进位加法器:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity add4 is
port (a:in std_logic_vector(3 downto 0);
b:in std_logic_vector(3 downto 0);
cin:in std_logic;
sum:out std_logic_vector(3 downto 0);
co:out std_logic);
end;
architecture behave of add4 is
signal c1,c2,c3,g1,g2,p1,p2:std_logic;
begin
sum(0)<=a(0) xor b(0) xor cin;
sum(1)<=a(1) xor b(1) xor c1;
sum(2)<=a(2) xor b(2) xor c2;
sum(3)<=a(3) xor b(3) xor c3;
c1<=(a(0) and b(0)) or ((a(0) or b(0)) and cin);
c2<=g1 or (p1 and c1);
c3<=g2 or (p2 and c2);
g1<=a(1) and b(1);g2<=a(2) and b(2);
p1<=a(1) or b(1);p2<=a(2) or b(2);
co<=(a(3)and b(3))or ((a(3)or b(3)) and (g2 or
(p2 and c2)));
end;
测试程序:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity test_add4 is
end;
architecture test_add4 of test_add4 is
component add4
port(a:in std_logic_vector(3 downto 0);
b:in std_logic_vector(3 downto 0);
cin:in std_logic;
sum:out std_logic_vector(3 downto 0);
co:out std_logic);
end component;
- 1
- 2
前往页