X hits on this document

56 views

0 shares

0 downloads

0 comments

11 / 14

If Statement

// File: simple_alu.h #include “systemc.h” const int WS=4;

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

SC_MODULE(simple_alu) sc_in<sc_uint<WS> > a, b; sc_in<bool> ctrl; sc_out< sc_uint<WS> > z; {

void simple_alu::prc_simple_alu(){

if(ctrl) z = a.read() & b.read();

else z = a.read() | b.read();

void prc_simple_alu();

}

SC_CTOR(simple_alu) { SC_METHOD(prc_simple_alu); sensitive << a << b << ctrl;

}

};

  • A. Milenkovic

If Statement: Priority encoder

// File: priority.h #include “systemc.h” const int IS=4; const int OS=3;

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

void priority::prc_priority(){ sc_uint<IS> tsel;

SC_MODULE(priority) { sc_in<sc_uint<IS> > sel; sc_out< sc_uint<OS> > z;

tsel = sel.read();

void prc_priority();

SC_CTOR(priority) { SC_METHOD(prc_priority); sensitive << sel;

}

if(tsel[0]) z = 0; else if (tsel[1]) z = 1; else if (tsel[2]) z = 2; else if (tsel[3]) z = 3; else z = 7;

}

};

  • A. Milenkovic

Switch Statement: ALU

// File: alu.h #include “systemc.h” const int WORD=4; enum op_type {add, sub, mul, div};

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

void priority::prc_alu(){ sc_uint<WORD> ta, tb;

SC_MODULE(alu) { sc_in<sc_uint<WORD> > a, b; sc_in<op_type> op; sc_out< sc_uint<WORD> > z;

ta = a.read(); tb = b.read();

switch (op) { case add: z = ta+tb; break;

void prc_alu();

SC_CTOR(alu) { SC_METHOD(prc_alu); sensitive << a << b << op;

}

}

case sub: z = ta–tb; break; case mul: z = ta*tb; break; case div: z = ta/tb; break;

}

};

  • A. Milenkovic

31

32

33

Document info
Document views56
Page views56
Page last viewedFri Dec 09 23:25:07 UTC 2016
Pages14
Paragraphs678
Words2716

Comments