Searching \ for 'STATUS flags' in subject line. ()
Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=status+flags
Search entire site for: 'STATUS flags'.

Truncated match.
'STATUS flags'
1998\01\28@203651 by

Hey all!

This is just a little somthing that I wanted to verify...

I am using 'subwf' on a 16C54 to compare two bytes, and I saw in the
programmers manual how the Carry flag is set... the Zero flag is still
set according to the result, correct?  Really, I'm doing a greater
than/less than/equal to thing, so, first I should check the Z flag to
see if the result was zero, if it was, I'll branch, if not, then test
the C flag and go from there, right?

So, when using 'subwf':
If (f) - (W) is positive,
(f) > (W) / Z = 0, C = 1.
If (f) - (W) is zero,
(f) = (W) / Z = 1, C = 1.
If (f) - (W) is negative,
(f) < (W) / Z = 0, C = 0.

Is everything I said about the flags correct?

Thanks again,
--
~Keith
tsk3000Prodigy.Net
http://pages.prodigy.net/tsk3000/
Keith Burzinski <tsk3000Prodigy.Net> wrote:

> I am using 'subwf' on a 16C54 to compare two bytes, and I saw in the
> programmers manual how the Carry flag is set... the Zero flag is
> still set according to the result, correct?

Correct, Keith.

> Really, I'm doing a greater than/less than/equal to thing, so,
> first I should check the Z flag to see if the result was zero, if
> it was, I'll branch, if not, then test the C flag and go from
> there, right?

Actually, it'll be faster to check the C flag first, then only
check the Z flag if the C flag was set... That way, you only
check one flag when the result is negative (a much more-likely
occurence than a "0" result).

> So, when using 'subwf':
> If (f) - (W) is positive,
>    (f) > (W) / Z = 0, C = 1.
> If (f) - (W) is zero,
>    (f) = (W) / Z = 1, C = 1.
> If (f) - (W) is negative,
>    (f) < (W) / Z = 0, C = 0.
>
> Is everything I said about the flags correct?

Yes, if you treat the contents of "f" and "w" as unsigned (i.e.,
non-negative) numbers.

-Andy

=== Andrew Warren - fastfwdix.netcom.com
=== Fast Forward Engineering - Vista, California
=== http://www.geocities.com/SiliconValley/2499
Andrew Warren wrote:
{Quote hidden}

Okay, this works!  Thanks!

Now I've run into another problem, though.  What's the quickest way to
check if a number is negative?  Can I just test bit 7?  I just tried
subtracting 0 from the register using 'subwf', but that seems to
_always_ leave the C flag set.  And if I add 0 using 'addwf', it always
leaves the C flag clear.  Will just tesing bit 7 of the reg always work?

Thanks again,
--
~Keith
tsk3000Prodigy.Net
http://pages.prodigy.net/tsk3000/
Keith Burzinski <tsk3000Prodigy.Net> wrote:

> What's the quickest way to check if a number is negative?  Can I
> just test bit 7?

Yes.

> I just tried subtracting 0 from the register using 'subwf', but
> that seems to _always_ leave the C flag set.

Of course it does; SUBWF treats the two numbers as UNSIGNED
(i.e., non-negative), so subtracting 0 always gives (as far as
SUBWF is concerned) a non-negative result.

> And if I add 0 using 'addwf', it always leaves the C flag clear.

This happens because the ADDWF instruction only sets the carry
flag if the result is greater than 255, and adding 0 to an 8-bit
number can NEVER result in an answer that's greater than 255.

> Will just tesing bit 7 of the reg always work?

Yes.

-Andy

=== Andrew Warren - fastfwdix.netcom.com
=== Fast Forward Engineering - Vista, California
=== http://www.geocities.com/SiliconValley/2499

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...