1
|
|
2
|
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc
|
3
|
|
4
|
-- This file is part of VESTs (Vhdl tESTs).
|
5
|
|
6
|
-- VESTs is free software; you can redistribute it and/or modify it
|
7
|
-- under the terms of the GNU General Public License as published by the
|
8
|
-- Free Software Foundation; either version 2 of the License, or (at
|
9
|
-- your option) any later version.
|
10
|
|
11
|
-- VESTs is distributed in the hope that it will be useful, but WITHOUT
|
12
|
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14
|
-- for more details.
|
15
|
|
16
|
-- You should have received a copy of the GNU General Public License
|
17
|
-- along with VESTs; if not, write to the Free Software Foundation,
|
18
|
-- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
|
20
|
-- ---------------------------------------------------------------------
|
21
|
--
|
22
|
-- $Id: ap_a_fg_a_03.vhd,v 1.2 2001-10-26 16:29:33 paw Exp $
|
23
|
-- $Revision: 1.2 $
|
24
|
--
|
25
|
-- ---------------------------------------------------------------------
|
26
|
|
27
|
-- code from book
|
28
|
|
29
|
library ieee; use ieee.std_logic_1164.all;
|
30
|
|
31
|
entity add_and_sub is
|
32
|
port ( a, b, c : in natural;
|
33
|
y : out natural;
|
34
|
ovf : out std_ulogic );
|
35
|
end entity add_and_sub;
|
36
|
|
37
|
--------------------------------------------------
|
38
|
|
39
|
library ieee; use ieee.numeric_std.all;
|
40
|
|
41
|
architecture rtl of add_and_sub is
|
42
|
signal stage2, stage3 : unsigned ( 8 downto 0 );
|
43
|
begin
|
44
|
stage2 <= To_unsigned(a, 9) + to_unsigned(b, 9); -- "+" from numeric_std
|
45
|
stage3 <= stage2 - c; -- "-" from numeric_std
|
46
|
y <= To_integer(stage3) ;
|
47
|
ovf <= stage3(8);
|
48
|
end rtl;
|
49
|
|
50
|
-- end code from book
|
51
|
|
52
|
|
53
|
|
54
|
entity fg_a_03 is
|
55
|
end entity fg_a_03;
|
56
|
|
57
|
|
58
|
library ieee;
|
59
|
use ieee.std_logic_1164.all, ieee.numeric_std.all;
|
60
|
|
61
|
architecture test of fg_a_03 is
|
62
|
|
63
|
signal a, b, c, y : natural := 0;
|
64
|
signal ovf : std_ulogic;
|
65
|
|
66
|
begin
|
67
|
|
68
|
dut : entity work.add_and_sub
|
69
|
port map ( a, b, c, y, ovf );
|
70
|
|
71
|
stimulus : process is
|
72
|
begin
|
73
|
wait for 10 ns;
|
74
|
a <= 2; b <= 5; c <= 3; wait for 10 ns;
|
75
|
a <= 192; b <= 192; wait for 10 ns;
|
76
|
a <= 10; b <= 11; c <= 22; wait for 10 ns;
|
77
|
|
78
|
wait;
|
79
|
end process stimulus;
|
80
|
|
81
|
end architecture test;
|