Re: A86: Re: Greater Than/Less Than
[Prev][Next][Index][Thread]
Re: A86: Re: Greater Than/Less Than
>> Anyway, p and m are for signed numbers (2s complement), c and nc are for
>> unsigned numbers.
>>
>
>Signed? Unsigned? Please, someone write a FAQ before I drive y'all nuts! :)
Oops, sorry. :-)
A byte has 8 bits, so it can hold 256 different values.
In an unsigned byte, these values are 0 to 255 ($00 to $FF).
In a signed byte, these values are -128 to +127. It works just the way
you'd expect it to. If you subtract 1 from 0 (in a byte) you get $FF, so in
a signed byte, $FF is -1. Similarly, $FE is -2, all the way down to $80 is
-128.
If you were comparing -128 ($80) and 1 ($01), using the carry flag, you
would get that -128 is greater. So you have to use the p/m (plus/minus)
flag, which keeps track of sign, and will give you the correct comparison
for signed numbers.
BTW, one's complement is NOT x, two's complement is NOT x + 1. . .
--Joshua
Follow-Ups:
References: