Comment 15 for bug 584093

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

Hi Anjhan,

Here is the what the 8080 manual says about DAA:

...following a two step process:

1. If the least significant four bits of the accumulator is represents a number greater than 9 or if the Auxiliary Carry bit is equal to one, the accumulator is increased by 6. Otherwise no increment occurs.
/*
What the code should do:

if (low > 9 || sys.flag.ac) { sys.reg.a += 6;....
*/

2. If the most significant four bits of the accumulator now[please NOTE the now, after adding 6 to the lower bits] represents a number greater than 9, or if the normal carry bit is equal to one, the most significant four bits are incremented by six. Otherwise no incrementing occurs.

/*
What the code should do:

get the most significant four bits and check the condition specified:
high = sys.reg.a >> 4;
   if (high > 9 || sys.flag.c)

increment the four bits by six:
sys.reg.a += (6 << 4);
*/

If a carry out the least significant occurs during Step(1), the Auxiliary Carry it is set; otherwise it is reset. Likewise, if a carry out of the most significant four bits occur during Step(2), the normal Carry bit is set; otherwise it is unaffected[NOTE].

/*
What the code should do:

In the first condition when we added 6 to the lower bits,
if((low + 6) > 15) sys.flag.ac = 1; else sys.flag.ac = 0;

6 is added because we are not updating the low variable after adding 6 to register a.

Similarly for normal Carry bit.

In the second step:
if((high + 6) > 15) sys.flag.c = 1;

notice that the flag is not unset if condition fails, as stated in the manual.
*/

Please let me know if I missed some logic, or am I using the wrong manual :)

Thanks,
Debjit