Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: Hot_Dog on May 06, 2011, 03:36:52 pm
-
If Zilog had wanted to, they could have made inc reg8 and dec reg8 affect the carry flag on teh Z80 processor. So I'm assuming there's a good reason they chose not to do so. Does anyone know the reason?
-
They don't affect the carry flag because the zero flag does pretty much the same thing, allowing data in the carry flag to be preserved. For inc reg8, the zero flag is affected in the exact way the carry flag would be affected, both of which would be set if the register was 0xFF before the operation. For dec reg8 it's not exactly the same, but it's very close. The zero flag would be set if the register was 0x01 whereas the carry flag would be set if the register was 0x00, but this can be easily corrected for by keeping the register's value at 1 above the value you actually want it to represent.
-
So the reason, then, is to preserve the carry flag?
-
Yes. There's no reason to affect the carry flag if you can look to another flag for (nearly) identical results. I've seen a few routines that rely on this lack of carry flag affecting to function optimally.
-
I wonder why DEC HL does not affect any flags, though.
-
The inc reg16 and dec reg16 instructions don't affect flags because they are very often used to simply advance a pointer in data as part of a routine that needs the flags for other information. Also, it's simple enough to make your own version that affects flags by using 8-bit inc or dec instead.
-
DEC HL does not affect any flags, not even the zero flag. I can see why you don't want to affect the carry flag, but DEC reg16 doesn't change flags at all.
EDIT: Ninja'd
EDIT2:
Also, it's simple enough to make your own version that affects flags by using 8-bit inc or dec instead.
Yeah, I guess. It would be nice to do that in one instruction, though. :\