4 Bit Ripple Carry Model
use ieee.std_logic_1164.all;
port ( a,b: in std_logic_vector(3 downto 0);
sum: out std_logic_vector(3 downto 0)
architecture bruteforce of adder4bit is
-- temporary signals for internal carries
signal c : std_logic_vector(4 downto 0); .
sum(0) <= a(0) xor b(0) xor c(0);
c(1) <= (a(0) and b(0)) or (c(0) and (a(0) or b(0)));
sum(1) <= a(1) xor b(1) xor c(1);
c(2) <= (a(1) and b(1)) or (c(1) and (a(1) or b(1)));
sum(2) <= a(2) xor b(2) xor c(2);
c(3) <= (a(2) and b(2)) or (c(2) and (a(2) or b(2)));
sum(3) <= a(3) xor b(3) xor c(3);
c(4) <= (a(3) and b(3)) or (c(3) and (a(3) or b(3)));
Straight forward implementation. Nothing wrong with this.
However, is there an easier way?