Project

General

Profile

Download (2.39 KB) Statistics
| Branch: | Tag: | Revision:
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: ch_09_fg_09_02.vhd,v 1.2 2001-10-26 16:29:34 paw Exp $
23
-- $Revision: 1.2 $
24
--
25
-- ---------------------------------------------------------------------
26

    
27
package fg_09_02_a is
28

    
29
  -- code from book (in text)
30

    
31
  function "+" ( bv1, bv2 : bit_vector ) return bit_vector;
32

    
33
  -- end code from book
34

    
35
end package fg_09_02_a;
36

    
37

    
38

    
39
package body fg_09_02_a is
40

    
41
  -- code from book
42

    
43
  function "+" ( bv1, bv2 : bit_vector ) return bit_vector is
44

    
45
    alias norm1 : bit_vector(1 to bv1'length) is bv1;
46
    alias norm2 : bit_vector(1 to bv2'length) is bv2;
47

    
48
    variable result : bit_vector(1 to bv1'length);
49
    variable carry : bit := '0';
50

    
51
  begin
52
    if bv1'length /= bv2'length then
53
      report "arguments of different length" severity failure;
54
    else
55
      for index in norm1'reverse_range loop
56
        result(index) := norm1(index) xor norm2(index) xor carry;
57
        carry := ( norm1(index) and norm2(index) )
58
                 or ( carry and ( norm1(index) or norm2(index) ) );
59
      end loop;
60
    end if;
61
    return result;
62
  end function "+";
63

    
64
  -- end code from book
65

    
66
end package body fg_09_02_a;
67

    
68

    
69

    
70

    
71
entity fg_09_02_b is
72
end entity fg_09_02_b;
73

    
74

    
75
architecture test of fg_09_02_b is
76

    
77
  use work.fg_09_02_a.all;
78

    
79
begin
80

    
81
  stimulus : process is
82
                       use std.textio.all;
83
                     variable L : line;
84
  begin
85
    write(L, X"0002" + X"0000");
86
    writeline(output, L);
87
    write(L, X"0002" + X"0005");
88
    writeline(output, L);
89
    write(L, X"0002" + X"FFFE");
90
    writeline(output, L);
91
    
92
    wait;
93
  end process stimulus;
94

    
95
end architecture test;
(166-166/267)