please dont rip this site

PIC Microcontoller Math Method

Increment / Decrement

Increment / Decrement 32 bit address and detect zero

; given address of 32 bit little-endian counter in W,
; increment or decrement the counter and return Z set if zero

;Inc32z 
;From Dmitry Kiryashov
inc32z:
        movwf   FSR
        clrz

        incfsz  INDF,F
        return

        incfsz  FSR,F
        incfsz  INDF,F
        return

        incfsz  FSR,F
        incfsz  INDF,F
        return

        incfsz  FSR,F
        incf    INDF,F
        return
;Dec32z
;From Rich Leggitt, Andrew Warren, and Dmitry Kiryashov
; 99.2% of the time, this takes 10 cycles w/call
dec32z:
        movwf   FSR
        decfsz  INDF,F
        goto    dec32nz

        incf    FSR,F
        movfw   INDF

        incf    FSR,F
        iorwf   INDF,W

        incf    FSR,F
        iorwf   INDF,W  ;get _Z finally
        return

dec32nz:
        clrz            ;set _Z=0
        incfsz  INDF,W
        return

        incfsz  FSR,F   ;doesn't corrupt _Z
        decfsz  INDF,F
        incfsz  INDF,W
        return

        incfsz  FSR,F   ;...
        decfsz  INDF,F
        incfsz  INDF,W
        return

        incfsz  FSR,F   ;...
        decfsz  INDF,F
        return
        return

;for the 18cxxx instruction set.
;From Scott Dattalo
; 10-16 cycles


dec32:
    movwf   FSR0L    ; the fsr's (three of them) on the 18cxxx
    clrf    FSR0H    ; are 16bits wide

    decf    POSTINC0,F,1 ;Indirect access that increments the fsr.

    bnz      dec32nz     ;this was bz

  ;The lsbyte is zero , so we don't need to propogate the borrow
  ;but we need to see if the higher bytes are zero.

    movf    POSTINC0,w,1 ;The first byte is zero
    iorwf   POSTINC0,w,1 ;check the next three
    iorwf   POSTINC0,w,1

    return

dec32nz
   ;decf on the 18cxxx parts affects C

    skpnc
     return

    decf   POSINC0,F,1
    skpc
     decf  POSTINC0,F,1

    skpc
     decf  POSTINC0,F,1

    clrz          ;was setz
    return


file: /Techref/microchip/math/incdec/32bitwz.htm, 2KB, , updated: 2000/2/11 14:56, local time: 2024/12/13 04:08,
TOP NEW HELP FIND: 
18.97.14.84:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://massmind.org/Techref/microchip/math/incdec/32bitwz.htm"> PIC Math Increment / Decrement 32 Bit and detect zero</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .