C after CMPS/CMPSX/ADDS/ADDSX/SUBS/SUBSX

124»

Comments

  • TonyB_TonyB_ Posts: 84
    edited October 11 Vote Up0Vote Down
    We've probably all had enough of signed arithmetic, so I'll try to make this my final thoughts on the matter.
    cgracey wrote: »
    Thanks for all the work you did on this, TonyB_.

    Is there such a thing as overflow when doing CMPS/CMPSX? Because you are just comparing, and not producing a 'difference', I think there's nothing that could be called overflow. Is that right? $8000_0000 compared to $0000_0001 is 'less than', so C=1. I'm a little punch drunk from all this signed stuff.

    CMPS is just SUBS without the result being saved, so yes there is an overflow and it will be used to generate the correct sign. TESTB D,#31 XORC relies on D[31] being the msb of the result, which it won't be with CMPS/CMPSX but that matters not one jot.
    cgracey wrote: »
    We could call it "correct sign", but maybe just "sign" would suffice. On the other hand, "correct sign" doesn't get mentally dismissed as easily.

    Plain "sign" would be interpreted as the sign bit of the result, I think. I like the name "correct sign" and what it is, the XOR combination of sign bit and overflow.

    XOR is a beautiful logical operation because it's reversible and there's no carry. After writing xoroshiro+ code for the Z80, I'm really tuned into XOR and I found it easier to represent two variables as a and a XOR b instead of simply a and b.

    Finally, Chip, could you please add TESTB D,#31 XORC somewhere in the docs, so that people know how to test for overflow? Thanks.
    Formerly known as TonyB
Sign In or Register to comment.