Getting wrong output while using multiple wait(SC_ZERO_TIME) in SystemC

I have recently started learning systemC and trying to build a simple adder in it. I have two input ports A and B and an output port out. I have used the following thread process, which is sensitive to A and B –

void adder::process()
{
  while (true)
  {
    wait();
    out.write(a.read() + b.read());
  }
}

The testbench function is –

 void mntr()
  {
    cout << "[" << sc_time_stamp() << "] " << a << " + " << b << " = " << out << endl;
  }

void test()
  {
    a = 1;
    b = 2;
    wait(SC_ZERO_TIME);
    a = 1;
    b = 1;
    wait(SC_ZERO_TIME);
    a = 4;
    b = 4;
    wait(SC_ZERO_TIME);
    a = 8;
    b = 8;
    wait(SC_ZERO_TIME);
  }

The mntr function is sensitive to OUT. If I use wait for some duration of time greater than zero, it works fine, but when I use SC_ZERO_TIME the output I’m getting is wrong.

Output ->
[0 s] 1 + 1 = 3
[0 s] 1 + 1 = 2
[0 s] 8 + 8 = 8
[0 s] 8 + 8 = 0

I do understand the concept of Delta cycle and SC_ZERO_TIME a little bit, according to which the value should have been updated in the update phase of the cycle.

Can someone please explain this?

Leave a Comment