piclist 1995\12\08\140304a >
Thread: Negative numbers?
face BY : Andrew Warren email (remove spam text)

Steven Addison <PICLIST.....spamspamMITVMA.MIT.EDU> wrote:

{Quote hidden}


It's simple.  After a subtraction, the Carry flag is set if the
result is positive, clear if it's negative.  Assuming that all three
values (your code, the upper threshold, and the lower threshold) are
8-bit unsigned numbers, and that you're using a 16Cxx part (NOT a
16C5x), the code to do what you want looks like this:

   MOVF    CODE,W          ;W = the value you're testing.
   ADDLW   -LOWER          ;Is it lower than "LOWER"?
   BNC     BAD             ;If so, it's bad.  Jump.
   ADDLW   -(UPPER-LOWER)  ;Otherwise, is it higher than "UPPER"?
   BC      BAD             ;If so, it's bad.  Jump.

   NOP                     ;Otherwise, it's good.  Do whatever here...

For those of you who care about such things, the standard "This code
has neither been tested nor assembled; you get what you pay for"
disclaimer applies.


Andrew Warren - spamBeGonefastfwdTakeThisOuTspamix.netcom.com
Fast Forward Engineering, Vista, California

See also: www.piclist.com/techref/index.htm?key=negative+numbers
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Negative numbers?

month overview.

new search...