Jump to content


  • Content Count

  • Joined

  • Last visited

  1. darrenxu

    how to link bool port with sc_int

    thank you Alan, I got it work
  2. darrenxu

    how to link bool port with sc_int

    i know how to link two full-adder as a two-bit-adder, but i have no ideal to write the code to link them for example i write the code like that sc_uint<2> num1_t, num2_t, sum2_t; sc_signal <bool> num1_s1, num1_s2, num2_s1, num2_s2, carry_in, sum_s1, sum_s2; num1_t=num1; num1_s1=num1_t[0]; num1_s2=num1_t[1]; num2_s1=num2_t[0]; num2_s2=num2_t[1]; sum2_t[0]=sum_s1; sum2_t[1]=sum_s2; sum2=sum2_t; f1->a( num1_s1 ); f1->b( num2_s1 ); f1->carry_in ( carry_in ); f1->sum ( sum_s1); f1->carry ( carry_in1); f2->a( num1_s2 ); f2->b( num2_s2 ); f2->carry_in( carry_in ); f2->sum( sum_s2); f2->carry ( carry_in2); if i put the green part in the SC_CTOR, the compiler will give me the errors, or i try to put that in prc_2_bit_adder, it also give me the error or incorrect results! i have used one week to modify my code , none of them are work.
  3. I am a beginner of systemC recently I did a practice it require using two full-adders to make a 2-bit-adder the code of full-adder is below //------------------------------- #include "systemc.h" SC_MODULE (full_adder){ sc_in<bool> a,b,carry_in; sc_out<bool> sum,carry; void prc_full_adder() { sum= a^b^carry; carry= ((a & b )|(a & carry_in)|(b & carry_in)); } SC_CTOR(full_adder) { SC_METHOD (prc_full_adder); sensitive<<a<<b<<carry_in; } }; //------------------------------------------- the code for two_bit_adder is written down below //------------------------------------------ #include "systemc.h" #include "full_adder.cpp" SC_MODULE(two_bit_adder){ sc_in < bool> carry_in0; sc_in < sc_uint<2> > num1 , num2; sc_out < bool > carry_in2; sc_out < sc_uint<2> > sum2; full_adder *f1, *f2; void prc_2_bit_adder() { } SC_CTOR(two_bit_adder) { SC_METHOD(prc_2_bit_adder); sensitive<<carry_in0<<num1<<num2; f1= new full_adder ("f1"); f2= new full_adder ("f2"); f1->a( ); f1->b( ); f1->carry_in ( ); f1->sum ( ); f1->carry ( ); f2->a( ); f2->b( ); f2->carry_in( ); f2->sum( ); f2->carry ( ); } ~ two_bit_adder() { delete f1; delete f2; } }; //----------------------- the problem is the red part, how to link them? because the instance only can be linked by sc_signals, all the io ports of the full-adder are single bit, however the num1,num2,sum2 are two bits width, as io ports and sc_signals in systemC don't support bit select, I have to use sc_uint to convert them, where I should write code for converting? in SC_CTOR or in the function prc_2_bit_adder? I tried both, none of them give me the correct answers or correct compiler results please help me thanks!