X hits on this document

55 views

0 shares

0 downloads

0 comments

9 / 14

Modeling Combinational Logic: Signed Arithmetic

// File: s_adder.h #include “systemc.h”

SC_MODULE(s_adder) { sc_in<sc_int<4> > a, b;

sc_out <sc_int<5> > sum;

void prc_s_adder();

SC_CTOR(s_adder) { SC_METHOD(prc_s_adder); sensitive << a << b;

}

};

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

v o i d s _ a d d e r : : p r c _ s _ a d d e r ( ) {

sum = a.read() + b.read(); }

  • A. Milenkovic

25

Modeling Combinational Logic: Signed Arithmetic (2)

// File: s_adder_c.h #include “systemc.h”

// File: s_adder.cpp #include “s_adder_c.h”

SC_MODULE(s_adder_c) { sc_in<sc_int<4> > a, b; sc_out <sc_int<4> > sum; sc_out <bool> carry_out;

void prc_s_adder_c();

void s_adder_c::prc sc_int<5> temp;

_

s adder c(){

_

_

temp = a.read() + b.read(); sum = temp.range(3,0); carry_out = temp[4];

}

SC_CTOR(s_adder_c) { S C _ M E T H O D ( p r c _ s _ a d d e r _ c ) sensitive << a << b; ;

}

};

  • A. Milenkovic

26

Modeling Combinational Logic: Relational Operators

// File: gt.h #include “systemc.h” const WIDTH=8;

SC_MODULE(gt) { sc_in<sc_int<4> > a, b;

sc_out <bool> z; void prc_gt(); SC_CTOR(gt) {

// File: gt.cpp #include “gt.h” void gt::prc_gt(){

};

}

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

sc_int<WIDTH> atemp, btemp;

atemp = a.read(); btemp = b.read();

z = sc_uint<WIDTH>(atemp.range(WIDTH/2-1,0)) > sc_uint<WIDTH>(btemp.range(WIDTH-1,WIDTH/2))

}

  • A. Milenkovic

27

Document info
Document views55
Page views55
Page last viewedFri Dec 09 17:44:42 UTC 2016
Pages14
Paragraphs678
Words2716

Comments