mahbod72 Posted August 7, 2015 Report Share Posted August 7, 2015 Hi is this memory definition is true? SC_MODULE(mem16) { sc_in <sc_lv <16> > in1; sc_out <sc_lv <16> > out1; sc_in <sc_lv <12> > addr; sc_in <bool> ld; sc_in_clk clk; int i; void write_data(); sc_lv <16> ram_data[4096]; SC_CTOR(mem16) { SC_METHOD(write_data); sensitive << addr << ld << in1 << clk ; //memory initialization ram_data[0]="0000000000000001"; ram_data[1]="0000000000000011"; ram_data[2]="0000000000000111"; ram_data[3]="0000000000001111"; ram_data[4]="0000000000011111"; ram_data[5]="0000000000111111"; ram_data[6]="0000000001111111"; //for (i=7; i++; i<4095) //ram_data[i] = 0; } }; void mem16::write_data() { out1 = ram_data[addr.read().to_int()]; if(clk){ if (ld) { ram_data[addr.read().to_int()] = in1; } } } Quote Link to comment Share on other sites More sharing options...
mahbod72 Posted August 7, 2015 Author Report Share Posted August 7, 2015 this code make run time error Quote Link to comment Share on other sites More sharing options...
apfitch Posted August 8, 2015 Report Share Posted August 8, 2015 Why not post the error message? Anyway, using to_int() looks bad to me, you don't want negative addresses. You should use to_uint(), regards Alan Quote Link to comment Share on other sites More sharing options...
mahbod72 Posted August 8, 2015 Author Report Share Posted August 8, 2015 good point sc_unit() is better i use this and problem is solved tank you sc_lv<12> addr_lv = addr.read(); sc_uint<12> add = addr_lv; out1 = ram_data[add]; if(clk){ if (ld) { ram_data[add] = in1; } 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.