I am new to systemC It might look stupid but I would appreciate help. In the below code
- In main function :write() to
aa
andbb
shows value 0 when read usingaa.read()
andbb.read()
which should be 10 and 20 - And also I think it should enter the method
do_add()
in the adder module as it is sensitive toa
andb
anda
,b
are binded toaa
andbb
signals but it doesn't call the methoddo_add()
. How does it work and is there any error in the code?
For compiling the code:
g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux64 -Wl,-rpath=$SYSTEMC_HOME/lib-linux64 -o out adder.cpp -lsystemc -lm
./out
#include "systemc.h"
#define WIDTH 32
SC_MODULE(adder) {
sc_in<sc_uint<WIDTH> > a, b;
sc_out<sc_uint<WIDTH> > sum;
void do_add() {
// cout<<"hello"<<endl;
// cout<<a.read()<<b.read()<<"\n";
sum.write(a.read() + b.read());
// cout<<sum.read()<<endl;
}
SC_CTOR(adder) {
SC_METHOD(do_add);
sensitive << a << b;
}
};
int sc_main(int argc, char* argv[]) {
sc_signal<sc_uint<WIDTH> >aa,bb;
adder add("Adder");
add.a(aa);
add.b(bb);
aa.write(10);
bb.write(20);
cout<<aa.read()<<bb.read()<<"\n";
}