Rashmi11 Posted April 9, 2015 Report Share Posted April 9, 2015 Hi All ,I am trying to copy a particular bit from one bit vector to other . I tried several ways of assigning the values but could not get it right. Also ,I want to assign a variable 'i' to a constant value in the loop . Below is the code . I have highlighted the lines where I am getting error. I would really appreciate if anyone could help in this . Thank you. #include "systemc.h" SC_MODULE(S_R){ sc_in <bool> clk; sc_in < sc_bv<8> > din; sc_in <bool> rst; sc_out< sc_bv<8> > dout; sc_in<bool> load; sc_bv<8> dinp; sc_int<1> i ; void shift() { if(rst) { dout=0; } else if(load) { dinp=din; i.write('0'); dout[0].write(dinp[7]); cout<<sc_time_stamp()<<"\tDESIGN1 --> input data:"<<dinp<<"\toutput data:"<<dout<<"\n"; } else { dinp=dinp<<1; dout.write(dinp[7]); i=i+1; cout<<sc_time_stamp()<<"\tDESIGN --> input data:"<<dinp<<"\toutput data:"<<dout<<"\n"; } } SC_CTOR(S_R) { SC_METHOD(shift); sensitive<<clk.pos(); } }; Quote Link to comment Share on other sites More sharing options...
apfitch Posted April 9, 2015 Report Share Posted April 9, 2015 Hi, the trick to understanding this is to notice the difference between sc_in < bool > dout [8]; // an array of 8 boolean ports and sc_in<sc_bv<8> > dout; // a single port containing an 8 bit vector. So you need to get at the 8 bit value within dout. The easiest way round it is probably sc_bv<8> dout_temp = dout.read(); dout_temp[0] = dinp.read()[7]; dout.write(dout_temp); For the use of sc_int<1>, sc_int is not a signal, therefore does not have a write() method. Just do i = 0; Generally if you're going to do code like you've shown above, I would recommend using temporary variables, then assigning the variables to the ports - or even easier, just use VHDL or Verilog :-) regards Alan David Black and Rashmi11 2 Quote Link to comment Share on other sites More sharing options...
dakupoto Posted April 10, 2015 Report Share Posted April 10, 2015 Hi All , I am trying to copy a particular bit from one bit vector to other . I tried several ways of assigning the values but could not get it right. Also ,I want to assign a variable 'i' to a constant value in the loop . Below is the code . I have highlighted the lines where I am getting error. I would really appreciate if anyone could help in this . Thank you. #include "systemc.h" SC_MODULE(S_R){ sc_in <bool> clk; sc_in < sc_bv<8> > din; sc_in <bool> rst; sc_out< sc_bv<8> > dout; sc_in<bool> load; sc_bv<8> dinp; sc_int<1> i ; void shift() { if(rst) { dout=0; } else if(load) { dinp=din; i.write('0'); dout[0].write(dinp[7]); cout<<sc_time_stamp()<<"\tDESIGN1 --> input data:"<<dinp<<"\toutput data:"<<dout<<"\n"; } else { dinp=dinp<<1; dout.write(dinp[7]); i=i+1; cout<<sc_time_stamp()<<"\tDESIGN --> input data:"<<dinp<<"\toutput data:"<<dout<<"\n"; } } SC_CTOR(S_R) { SC_METHOD(shift); sensitive<<clk.pos(); } }; Hello, A bit vector is a C++ RTL vector. So, have you looked into the possibility of using a copy constructor ? I am sure the basic C++ STL vector supports a cop constructor, so this ought to work. Rashmi11 1 Quote Link to comment Share on other sites More sharing options...
Rashmi11 Posted April 16, 2015 Author Report Share Posted April 16, 2015 Thank you both.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.