ankit Posted March 11, 2014 Report Share Posted March 11, 2014 1) I followed following steps to execute and to debug but could not see use of debugger a) g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux -o out stack_class.cpp -lsystemc -lm gdb out c) b sc_main d) run ------failed to see step-by-step output 2) if in switch i interchange wait and notify statement it give incorrect output. I wish to know how scheduler is working 3) i have used most of C++ as when i used more of systemC constructs such as ( read, write, sc_in, sc_out ) it leads to numerous error. 4) seek guidance to implement stack code in systemc in whatsoever best possible optimized manner #include "systemc.h" #include "iostream" using namespace std; SC_MODULE (stack_1) { sc_event e1,e2; sc_int<10> ch,num,top,space_left; sc_int<10> a[5]; SC_CTOR(stack_1) { top=0; SC_METHOD(read_1); sensitive<<e1; dont_initialize(); SC_METHOD(write_1); sensitive<<e2; dont_initialize(); SC_THREAD(sync); } void sync() { cout<<"\n***** MY STACK CODE *****"; do { cout<<"\nInput READ(0) or write(1)"; cin>>ch; switch(ch) { case 1: e2.notify(); wait(5,SC_SEC); cout<<"\n@"<<sc_time_stamp(); break;d case 0: e1.notify(); wait(5,SC_SEC); cout<<"\n@"<<sc_time_stamp(); break; default: cout<<"bad choice"; break; } }while(ch==0 || ch==1); } void read_1() { if(top==0) { cout<<"\nStack Underflow--cannot read"; } else { top --; cout<<"\nRead element is:"; cout<<a[top]; } } void write_1() { if(top==5) { cout<<"\nStack Overflow--cannot write"; } else { cout<<"\nenter element to write:"; cin>>num; a[top++]=num; } } }; int sc_main(int argc,char* argv[]) { stack_1 s("s"); sc_start(100,SC_SEC); return (0); } Quote Link to comment Share on other sites More sharing options...
dakupoto Posted March 11, 2014 Report Share Posted March 11, 2014 1) I followed following steps to execute and to debug but could not see use of debugger a) g++ -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux -o out stack_class.cpp -lsystemc -lm gdb out c) b sc_main d) run ------failed to see step-by-step output 2) if in switch i interchange wait and notify statement it give incorrect output. I wish to know how scheduler is working 3) i have used most of C++ as when i used more of systemC constructs such as ( read, write, sc_in, sc_out ) it leads to numerous error. 4) seek guidance to implement stack code in systemc in whatsoever best possible optimized manner #include "systemc.h" #include "iostream" using namespace std; SC_MODULE (stack_1) { sc_event e1,e2; sc_int<10> ch,num,top,space_left; sc_int<10> a[5]; SC_CTOR(stack_1) { top=0; SC_METHOD(read_1); sensitive<<e1; dont_initialize(); SC_METHOD(write_1); sensitive<<e2; dont_initialize(); SC_THREAD(sync); } void sync() { cout<<"\n***** MY STACK CODE *****"; do { cout<<"\nInput READ(0) or write(1)"; cin>>ch; switch(ch) { case 1: e2.notify(); wait(5,SC_SEC); cout<<"\n@"<<sc_time_stamp(); break;d case 0: e1.notify(); wait(5,SC_SEC); cout<<"\n@"<<sc_time_stamp(); break; default: cout<<"bad choice"; break; } }while(ch==0 || ch==1); } void read_1() { if(top==0) { cout<<"\nStack Underflow--cannot read"; } else { top --; cout<<"\nRead element is:"; cout<<a[top]; } } void write_1() { if(top==5) { cout<<"\nStack Overflow--cannot write"; } else { cout<<"\nenter element to write:"; cin>>num; a[top++]=num; } } }; int sc_main(int argc,char* argv[]) { stack_1 s("s"); sc_start(100,SC_SEC); return (0); } Hello Sir, A statck is a LIFO -- Last In First Out. For starters, implement this in simple C/C++ -- that is NO SystemC. Run it and verify that it works correctly -- add elements - remove some and verify that the Last In First Out order is maintained. A simple stack can be implemented as an array. The last element added is removed first -- adding an element increments the array index, and removing an element decrements it. Ensure array bound checking at each addition/removal. Try this out in plain C. When you have got it working just right, translate it to SystemC. However, SystemC does not offer any built in stack. Hope that helps. Quote Link to comment Share on other sites More sharing options...
David Black Posted March 11, 2014 Report Share Posted March 11, 2014 In your compilation (step 1a) you forgot to add the -g option to get debugging information into the resulting executable. % g++ -ggdb -I. -I$SYSTEMC_HOME/include -L. -L$SYSTEMC_HOME/lib-linux -o out stack_class.cpp -lsystemc -lm 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.