Bob Fehrenbach email (remove spam text)
>Here's an excerpt from a "comparison" tip page I'm working on:
>Testing that a value lies within a range
>In this example, the value in the W register will be tested to determine
>whether it lies within the range specified by the constants loval and hival
>(inclusive). In other words, we're testing loval <= W <= hival.
> addlw 256-hival
> addlw (hival-loval)+1
> btfsc status,cf
> goto inrange
Let's try this with w = 254, hival = 255, loval = 253.
254 + (256 - 255) = 255
255 + (255 - 253 + 1) = 258
which generates a carry.
Now try w = 75, hival = 100, loval = 50
75 + (256 - 100) = 231
231 + (100 - 50 +1) = 252
which does not generate a carry.
In both cases the starting value is in range. Did I miss something?
Bob Fehrenbach Wauwatosa, WI execpc.combfehrenb
In reply to: <199512090215.UAA14164@execpc.com>
See also: www.piclist.com/techref/index.htm?key=negative+numbers
You must be a member of the
piclist mailing list
(not only a www.piclist.com member) to post to the