Flags not set properly after DAA

Bug #745461 reported by Dinesh Sharma
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gnusim8085
New
Undecided
Unassigned

Bug Description

Flags are not being set properly after DAA. Consider the following code:
MVI A, 099H
ADI 01H
DAA
after this, the result should be 00 with carry set, which it is. However, the sign flag is set and Zero flag is cleared. It should be the other way round. The bug is perhaps caused by setting these flag before doing the final DAA adjustments, when the result was 9A, which would set the sign flag and clear the Z flag. After correction, the result is 00, so sign flag should be cleared, while the Z flag should be set.

Revision history for this message
Debjit Biswas (debjitbis08) wrote :

I believe the below code, which is part of the DAA instruction code is the reason for this bug:

  if (sys.reg.a > 0x99 || sys.flag.c)
  {
    sys.reg.a = sys.reg.a + 0x60;
    sys.flag.c = 1;
  }

After this operation there are no statements to modify the flags. When this condition is not activated the function _eef_inst_func_add_i is called which in turn calls the _eef_find_and_set_flags function and thus there is no issues.

It should have been something like this:

  if (sys.reg.a > 0x99 || sys.flag.c)
  {
    sys.reg.a = sys.reg.a + 0x60;
    sys.flag.c = 1;
    _eef_find_and_set_flags (sys.reg.a);
  }

Revision history for this message
Dinesh Sharma (iitdinesh) wrote :

In fact, I had reached the same conclusion and added the call to the code and recompiled gnusim8085. This solved the problem.

However, it is my impression that sufficient attention has not been paid to flag setting. I think the dcr instruction should set all flags except carry. I find that it is not setting the auxiliary carry flag. On the other hand, inr does set ac, as required. Since updates to gnusim8085 are so infrequent, we should start releasing versions with bugfixes with a minor version number changed. I shall be happy to test the programme and offer bug fixes when I can.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.