Half Adder Structural Model
Half Adder Structural Model
begin
x1: xor2 port map (a,b,sum);
a1: and2 port map (a,b,carry);
end structural;
Full Adder Structural model Test Bench coding
library IEEE;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL; use IEEE.std_logic_1164.all;
entity HA is entity adder_process_tb is
Port ( A,B : in STD_LOGIC; end entity;
S,C : out STD_LOGIC); architecture tb of adder_ff_process_tb is
end HA; component FAdder is
architecture dataflow of HA is Port ( FA, FB, FC : in STD_LOGIC;
begin FS, FCA : out STD_LOGIC);
S <= A XOR B; end component;
C <= A AND B; signal FA, FB, FC, FS, FCA : STD_LOGIC;
end dataflow; begin
uut : FAdder port map(
entity ORGATE is FA =>FA, FB =>FB,
Port ( X,Y : in STD_LOGIC; FC => FC, FS => FS, FCA => FCA);
Z : out STD_LOGIC); stim : process
end ORGATE; begin
architecture dataflow of ORGATE is FA <= '0';
begin FB <= '0';
Z <= X OR Y; FC <= '0';
end dataflow; wait for 10 ns;
assert ((FS = '0') and (FCA = '0'))
entity FAdder is report "test failed for input combination 000"
severity error;
Port ( FA, FB, FC : in STD_LOGIC;
FS, FCA : out STD_LOGIC);
FA <= '0';
end FAdder;
FB <= '0';
FC <= '1';
architecture structural of FAdder is
wait for 10 ns;
component HA is assert ((FS = '1') and (FCA = '0'))
Port ( A,B : in STD_LOGIC; report "test failed for input combination 001"
severity error;
S,C : out STD_LOGIC);
end component;
FA <= '0';
component ORGATE is
FB <= '1';
Port ( X,Y: in STD_LOGIC;
FC <= '0';
Z: out STD_LOGIC);
wait for 10 ns;
end component;
assert ((FS = '1') and (FCA = '0'))
SIGNAL S0,S1,S2:STD_LOGIC;
report "test failed for input combination 010"
begin
severity error;
U1:HA PORT
MAP(A=>FA,B=>FB,S=>S0,C=>S1);
FA <= '0';
U2:HA PORT
MAP(A=>S0,B=>FC,S=>FS,C=>S2); FB <= '1';
U3:ORGATE PORT FC <= '1';
MAP(X=>S2,Y=>S1,Z=>FCA);
wait for 10 ns;
end structural;
assert ((FS = '0') and (FCA = '1'))
report "test failed for input combination 011"
severity error;
FA <= '1';
FB <= '0';
FC <= '0';
wait for 10 ns;
assert ((FS = '1') and (FCA = '0'))
report "test failed for input combination 100"
severity error;
FA <= '1';
FB <= '0';
FC <= '1';
wait for 10 ns;
assert ((FS = '0') and (FCA = '1'))
report "test failed for input combination 101"
severity error;
FA <= '1';
FB <= '1';
FC <= '0';
wait for 10 ns;
assert ((FS = '0') and (FCA = '1'))
report "test failed for input combination 110"
severity error;
FA <= '1';
FB <= '1';
FC <= '1';
wait for 10 ns;
assert ((FS = '1') and (FCA = '1'))
report "test failed for input combination 111"
severity error;
wait;
end process;
end tb;