Searching \ for 'Adding two 32 bit numbers' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=adding+two+bit+numbers
Search entire site for: 'Adding two 32 bit numbers'.

Truncated match.
PICList Thread
'Adding two 32 bit numbers'
1997\02\20@094318 by Ed Todd

picon face
Here is the way I do it for 16 bit in assembler.  There are some simple
macros I use based on the CARRY bit too.

       MOVFW   A3
       ADDWF   B3,F
       IFCARRY
       INCF            B2,F
       MOVFW   A2
       ADDWF   B2,F
       IFCARRY
       INCF            B1,F
       MOVFW   A1
       ADDWF   B1,F
       IFCARRY
       INCF            B0,F
       MOVFW   A0
       ADDWF   B0,F
       IFCARRY
       GOTO            OVERFLOW

 <spam_OUTedtoddTakeThisOuTspamsni.net>    Ed Todd

1997\02\20@115652 by John Dammeyer

flavicon
face
Does that work for:

  0x0000ffff
+ 0x00000001
  ----------
  0x00010000

or does it result in
  0x00000000

ie:
if B2 is already 0xff then the INCF B2,F makes it zero but doesn't propogate
the new carry either as an overflow or into the next bytes.

John


At 07:34 AM 20/02/1997 -0700, you wrote:
{Quote hidden}

Pioneers are the ones, face down in the mud,
with arrows in their backs.
Automation Artisans Inc.      Ph. 1-250-544-4950
PO Box 20002                  Fax 1-250-544-4954
Sidney, BC CANADA V8L 5C9

1997\02\20@121711 by Craig Knotts

flavicon
face
    This method won't work for 32 bits if B2, B1, or B0 is 0xFF before the
    add and a carry occurs after an add operation.  The carry out from B2
    or B1 will be lost before the next add.

______________________________ Reply Separator _________________________________
Subject: Adding two 32 bit numbers
Author:  Ed Todd <edtoddspamKILLspamSNI.NET> at Internet
Date:    2/20/97 7:34 AM


Here is the way I do it for 16 bit in assembler.  There are some simple
macros I use based on the CARRY bit too.

       MOVFW   A3
       ADDWF   B3,F
       IFCARRY
       INCF            B2,F
       MOVFW   A2
       ADDWF   B2,F
       IFCARRY
       INCF            B1,F
       MOVFW   A1
       ADDWF   B1,F
       IFCARRY
       INCF            B0,F
       MOVFW   A0
       ADDWF   B0,F
       IFCARRY
       GOTO            OVERFLOW

 <.....edtoddKILLspamspam.....sni.net>    Ed Todd

1997\02\20@172545 by Andrew Warren

face
flavicon
face
Ed Todd <EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU> wrote:

> Here is the way I do it for 16 bit in assembler.  There are some
> simple macros I use based on the CARRY bit too.
>
>         MOVFW   A3
>         ADDWF   B3,F
>         IFCARRY
>         INCF            B2,F
>         MOVFW   A2
>         ADDWF   B2,F
>         IFCARRY
>         INCF            B1,F
>         MOVFW   A1
>         ADDWF   B1,F
>         IFCARRY
>         INCF            B0,F
>         MOVFW   A0
>         ADDWF   B0,F
>         IFCARRY
>         GOTO            OVERFLOW

Ed:

Your code is essentially the same as the example that started this
thread.  Like that example, it won't work.

Use your routine to perform the following two additions (each of
which should give the same result):

     0000FFFF        00000001
   + 00000001      + 0000FFFF

See why it fails?

-Andy

=== Andrew Warren - fastfwdspamspam_OUTix.netcom.com
=== Fast Forward Engineering - Vista, California
===
=== Custodian of the PICLIST Fund -- For more info, see:
=== www.geocities.com/SiliconValley/2499/fund.html

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