[A83] Re: positive/negative flags
[Prev][Next][Index][Thread]
[A83] Re: positive/negative flags
> From: "Tom" <caffeine43@netzero.net>
>
> Can anyone explain how I could use the P and M flags to see if a
> number is between two other numbers? Thanks!
> -Tom
> caffeine43@netzero.net on 06/19/2001
Actually the P and M flags are only used with signed bytes. These are
actually 7 bit numbers and then the 8th bit of the byte indicates the sign
(0 positive; 1 negative). So when you compare/subtract/add numbers the P/M
flag will have the same value as bit 7 as to check if the result is a
negative or positive number.
Normally to check if one number is smaller/greater than another one, you use
the carry, which is set whenever you pass by zero. So with an addition it is
set when the result is 256 or bigger (>=0), and with a
subtraction/comparison it is set when the result is less than zero (<=255).
To come to your question, to check if a number is between two others you
have to do 2 comparisons.
;acc is number to check
;b is lower bound
;c is upper bound
cp b
jr c,notgood ; carry set? yes, then b is bigger, nok
cp c
jr nc,notgood ; carry set? yes, then c is bigger, ok
...
notgood:
...
Tijl Coosemans
References: