piclist 1995\12\13\225224a >
Thread: Negative numbers?
www.piclist.com/techref/index.htm?key=negative+numbers
picon face BY : 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   @spam@bfehrenbspam_OUTspamKILLspamexecpc.com
<9512140352.AA03536@MIT.EDU>

In reply to: <199512090215.UAA14164@execpc.com>
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...