PIC Microcontoller Subtraction Math Method

16 bit subtraction with borrow

  Rudy Wieser

;----------------------------
; 16-bit Subtraction-with-Borrow
;       SourceH:SourceL - Number to be subtracted
;       Carry - NOT( Borrow to be subtracted )
;       DestH:DestL - Number to be subtracted FROM
;Out    DestH:DestL - Result
;       Carry - NOT( Borrow result)

        movf    SourceL,W
        subwf   DestL
        movf    SourceH,W
        btfss   STATUS,C
        incfsz  SourceH,W
        subwf   DestH           ;dest = dest - source, WITH VALID CARRY
                                ;(although the Z flag is not valid).

;----------------------------

Interested:

Comments: