-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtb_full_adder.vhd
65 lines (61 loc) · 2.2 KB
/
tb_full_adder.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-- 1-bit full adder testbench
-- modified from ghdl adder testbench example
-- A testbench has no ports
library ieee;
use ieee.std_logic_1164.all;
entity tb_full_adder is
end tb_full_adder;
architecture bhv of tb_full_adder is
-- with '93, component does not
-- need to be declared anymore
signal a, b, cin : std_logic;
signal s0, s1, cout0, cout1 : std_logic;
begin
-- instantiate full_adder component
-- syntax: entity work.entity_name(arch_name)
f0: entity work.full_adder(bhv)
port map (a => a, b => b, cin => cin, s => s0, cout => cout0);
f1: entity work.full_adder(str)
port map (a => a, b => b, cin => cin, s => s1, cout => cout1);
process
type pattern_type is record
-- inputs of the adder.
a, b, cin : std_logic;
-- expected outputs of the adder.
s, cout : std_logic;
end record;
-- patterns to apply.
type pattern_array is array (natural range <>) of pattern_type;
constant patterns : pattern_array :=
(('0', '0', '0', '0', '0'),
('0', '0', '1', '1', '0'),
('0', '1', '0', '1', '0'),
('0', '1', '1', '0', '1'),
('1', '0', '0', '1', '0'),
('1', '0', '1', '0', '1'),
('1', '1', '0', '0', '1'),
('1', '1', '1', '1', '1'));
begin
-- check each pattern.
for i in patterns'range loop
-- Set the inputs.
a <= patterns(i).a;
b <= patterns(i).b;
cin <= patterns(i).cin;
-- wait for the results.
wait for 1 ns;
-- check the outputs.
assert s0 = patterns(i).s
report "bad sum value" severity error;
assert s1 = patterns(i).s
report "bad sum value" severity error;
assert cout0 = patterns(i).cout
report "bad carray out value" severity error;
assert cout1 = patterns(i).cout
report "bad carray out value" severity error;
end loop;
assert false report "end of test" severity note;
-- wait forever; this will finish the simulation.
wait;
end process;
end bhv;