X hits on this document

43 views

0 shares

0 downloads

0 comments

5 / 14

SystemC Half Adder

// File half_adder.h #include “systemc.h”

// File half_adder.cpp #include “half_adder.h”

SC_MODULE(half_adder) { sc_in<bool> a, b; sc_out<bool> sum, carry;

void

h a l f _ a d d e r : : p r c _ h a l f _ a d d e r ( sum = a ^ b; )

{

carry = a & b;

void prc_half_adder();

}

SC_CTOR(half_adder) {

SC_METHOD(prc_half_adder); sensitive << a << b;

}

};

  • A. Milenkovic

13

SystemC Decoder 2/4

// File decoder2by4.h #include “systemc.h”

// File decoder2by4.cpp #include “decoder2by4.h”

SC_MODULE(decoder2by4) { sc_in<bool> enable;

void decoder2by4::prc {

_

decoder2by4()

sc_in<sc_uint<2> > select; sc_out<sc_uint<4> > z;

if (enable) { switch(select.read()) {

void prc_decoder2by4();

case 0: z=0xE; break; case 1: z=0xD; break;

SC_CTOR(decoder2by4) { SC_METHOD(prc_half_adder); sensitive(enable, select);

}

} } else

case 2: z=0xB; break; case 3: z=0x7; break;

};

z=0xF;

}

Note: Stream vs. Function notation

sensitive << a << b; sensitive(a, b);

// Stream notation style // Function notation style

  • A. Milenkovic

14

Hierarchy: Building a full adder

// File full_adder.h #include “systemc.h”

// a destructor ~full_adder() {

SC_MODULE(full_adder) { sc_in<bool> a,b,carry_in; sc_out<bool> sum,carry_out; sc_signal<bool> c1, s1, c2; void prc_or(); half_adder *ha1_ptr, *ha2_ptr;

SC_CTOR(full_adder) { ha1_ptr = new half_adder(“ha1”);

ha1_ptr->a(a); ha1_ptr->b(b); ha1_ptr->sum(s1);

ha1_ptr->carry(c1); ha2_ptr = new half_adder(“ha2”); (*ha2_ptr)(s1, carry_in,sum,c2); SC_METHOD(prc_or); sensitive << c1 << c2;

delete ha1_ptr; delete ha2_ptr;

}

};

// File: full_adder.cpp #include “full_adder.h”

void full_adder::prc_or(){ carry out = c1 | c2;

_

}

}

  • A. Milenkovic

15

Document info
Document views43
Page views43
Page last viewedWed Nov 30 06:31:11 UTC 2016
Pages14
Paragraphs678
Words2716

Comments