limiting to "no less than" zero


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    STATUS is a register in the PIC that contains the results (status) of arithmetic operations.
    Depening on the chip family, it may also have Watchdog Timer status and FSR/page bits.

    STATUS.0 is the CARRY flag.
    After an addition, if the result is larger than 255 the carry bit will be set (1).
    After a subtraction, if the result is less than 0 (BORROW), the carry bit will be cleared (0).

    The carry bit is only valid after addition/subtraction with 8-bit values.
    After math with WORD values, the carry bit cannot be used because not all of the math is done by the hardware.
    DT

  2. #2
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Quote Originally Posted by Darrel Taylor View Post
    The carry bit is only valid after addition/subtraction with 8-bit values.
    After math with WORD values, the carry bit cannot be used because not all of the math is done by the hardware.
    OK, curiosity got me so I tried it with WORD values and it still seems to work...


    x = 32768
    Y = 32769
    x = x + y
    Result: X = 1, STATUS.0 = 1
    '--------------------------------

    x = 32768
    Y = 32765
    x = x + y
    Result: X = 65533, STATUS.0 = 0
    '-------------------------------------

    x = 32768
    Y = 32765
    x = x - y
    Result: X = 3, STATUS.0 = 1
    '--------------------------------------

    x = 32765
    Y = 32771
    x = x - y
    Result: X = 65530, STATUS.0 = 0
    '------------------------------------


    I thought it was only 'sposed to work with 8 bit numbers?


    Steve

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Try it with ...

    X = 32768
    Y = 65523
    DT

  4. #4
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Quote Originally Posted by Darrel Taylor View Post
    Try it with ...

    X = 32768
    Y = 65523
    Nope, that didn't work.
    OK, 8 bit math then....

    Thanks!

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    Since PBP handles the 16 (31) bit math, and certainly knows the results of the 8 bit operation, the writers of PBP *could* provide us with an overflow/underflow flag (PSTATUS?). If they really wanted to.
    Charles Linquist

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts