Searching \ for '16 bit subtract example ???' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=bit+subtract+example
Search entire site for: '16 bit subtract example ???'.

Truncated match.
PICList Thread
'16 bit subtract example ???'
1997\03\28@211016 by Bob Segrest

picon face
Greetings,

I am afraid that my binary math knowledge has waned over the years...  Can
anyone provide me with a sixteen bit subtraction routine example ???

The quibble of course is how to manage the carry (borrow bit).....

Bob Segrest

1997\03\28@213120 by Bob Fehrenbach

picon face
Bob Segrest <spam_OUTbobslanTakeThisOuTspamEROLS.COM> wrote:
>Can
>anyone provide me with a sixteen bit subtraction routine example ???

  Try these:

;*******************************************************************
;  Two byte subtract.
;  At exit, if C = 1, result is positive.
;  Usage example:   sub_word new_count, old_count
;  Note: Zero flag NOT valid at exit
;*******************************************************************

sub_word: macro aaa, bbb
  movf    (bbb+1), w
  subwf   (aaa+1), f
  movf    (bbb), w
  skpc
  incfsz  (bbb), w
  subwf   (aaa), f
  endm

;*******************************************************************
;  Subtract two byte literal.
;  At exit, C = 0 if result is negative
;  Note: Zero flag NOT valid at exit
;*******************************************************************

sub_word_literal: macro aaa, lll

  movlw   low (~(lll) + 1)
  addwf   aaa+1, f
  movlw   high ((~(lll) + 1) & h'ffff')
  skpnc
  addlw   1
  skpnc
  skpz
  addwf   aaa, f
  endm

;*******************************************************************

--
Bob Fehrenbach    Wauwatosa, WI     .....bfehrenbKILLspamspam@spam@execpc.com

1997\03\29@194507 by Tom Handley

picon face
  Bob, the routines from Microchip's AN-526 work fine. I use the Parallax
assembler but the routines are in Microchip's format. They are:

ACCaLO  DS      1               ; Accumulator A LSB
ACCaHI  DS      1               ; Accumulator A MSB
ACCbLO  DS      1               ; Accumulator B LSB
ACCbHI  DS      1               ; Accumulator B MSB

; Double Precision Subtraction ( ACCb - ACCa -> ACCb )

Dsub
       CALL    neg_A

; Double Precision Addition ( ACCb + ACCa -> ACCb )

Dadd    movf    ACCaLO,w        ; Addition
       addwf   ACCbLO          ; add lsb
       btfsc   STATUS,CARRY    ; add in carry
       incf    ACCbHI
       movf    ACCaHI,w
       addwf   ACCbHI          ; add msb
       retlw   0

neg_A
       COMF    ACCaLO
       INCF    ACCaLO
       BTFSC   STATUS,Z_bit
       DECF    ACCaHI
       COMF    ACCaHI
       RETLW   0
--------

  - Tom

At 09:06 PM 3/28/97 -0500, you wrote:
>Greetings,
>
>I am afraid that my binary math knowledge has waned over the years...  Can
>anyone provide me with a sixteen bit subtraction routine example ???
>
>The quibble of course is how to manage the carry (borrow bit).....
>
>Bob Segrest
>
>

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...