ex_adder: full_adder.h

File full_adder.h, 698 bytes (added by fpecheux, 15 years ago)
Line 
1// File : full_adder.h
2#include "half_adder.h"
3
4SC_MODULE(full_adder)
5{
6        sc_in<bool> a,b,carry_in;
7        sc_out<bool> sum,carry_out;
8
9        sc_signal<bool> c1,s1,c2;
10        void prc_or();
11
12        half_adder *ha1_ptr,*ha2_ptr;
13
14        SC_CTOR(full_adder) : a("a"),b("b"),carry_in("carry_in"),
15                                sum("sum"), carry_out("carry_out"),
16                                c1("c1"),s1("s1"),c2("c2")
17        {
18                ha1_ptr=new half_adder("ha1");
19                // Named association:
20                ha1_ptr->a(a);
21                ha1_ptr->b(b);
22                ha1_ptr->sum(s1);
23                ha1_ptr->carry(c1);
24
25                ha2_ptr=new half_adder("ha2");
26                // Positional association:
27                (*ha2_ptr)(s1,carry_in,sum,c2);
28
29                SC_METHOD(prc_or);
30                sensitive << c1 << c2;
31        }
32
33        // A destructor
34        ~full_adder()
35        {
36                delete ha1_ptr;
37                delete ha2_ptr;
38        }
39};
40