library ieee;
use ieee.std_logic_1164.all;
entity fa isport(a,b,ci : instd_logic;
s,co : outstd_logic);
end fa;
architecture b_fa of fa isbegin
s<=a xor b xor ci;
co<=((a xor b) and ci) or (a and b);
end b_fa;
二. 使用刚设计的全加器设计
library ieee;
use ieee.std_logic_1164.all;
entity adder8 isport(a,b : instd_logic_vector(7downto0);
ci,m : instd_logic;
s : outstd_logic_vector(7downto0);
co ,vf: outstd_logic);
end adder8;
architecture s_adder8 of adder8 iscomponent fa isport(a,b,ci : instd_logic;
s,co : outstd_logic);
endcomponent;
signal c: std_logic_vector(7downto1);
begin
cm1 : fa portmap(a(0),b(0) xor m,ci,s(0),c(1));
cm2 : fa portmap(a(1),b(1) xor m,c(1),s(1),c(2));
cm3 : fa portmap(a(2),b(2) xor m,c(2),s(2),c(3));
cm4 : fa portmap(a(3),b(3) xor m,c(3),s(3),c(4));
cm5 : fa portmap(a(4),b(4) xor m,c(4),s(4),c(5));
cm6 : fa portmap(a(5),b(5) xor m,c(5),s(5),c(6));
cm7 : fa portmap(a(6),b(6) xor m,c(6),s(6),c(7));
cm8 : fa portmap(a(7),b(7) xor m,c(7),s(7),co);
vf<=c(6) xor c(7); -- vf 为溢出信号end s_adder8;