Searching \ for 'Someone tell me if I'm blind' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/index.htm?key=someone+tell+blind
Search entire site for: 'Someone tell me if I'm blind'.

Truncated match.
PICList Thread
'Someone tell me if I'm blind'
1999\01\09@215420 by Keith Causey

flavicon
face
Hello All,
   I am trying to debug a simple routine that adds two 32 bit numbers and I
can't figure out why it keeps setting bits in the hi order bytes
inappropriately. If you will take a look at this code and give some
suggestions they would be much appreciated. The two arguments are in eight
locations. Arg. 1 is, from least to most significant, in registers da1_l
da1_m da1_h and da1_x. Arg. 2 is in da2_l da2_m da2_h and da2_x. On exit the
sum is supposed to be in da1_l da1_m da1_h and da1_x.
Here it is:
 movf da2_l, W
 addwf da1_l, SAME
 btfsc CARRY
 incf da2_m, SAME
 btfsc ZERO
 incf da2_h, SAME
 btfsc ZERO
 incf da2_x, SAME
 movf da2_m, W
 addwf da1_m, SAME
 btfsc CARRY
 incf da2_h, SAME
 btfsc ZERO
 incf da2_x, SAME
 movf da2_h, W
 addwf da1_h, SAME
 btfsc CARRY
 incf da2_x, SAME
 movf da2_x, W
 addwf da1_x, SAME
                                       If you look at this code
                                       Many Thanks
                                       Keith Causey

1999\01\09@235806 by Chip Weller

flavicon
face
Keith Causey wrote:


>Hello All,
>    I am trying to debug a simple routine that adds two 32 bit numbers and
I
>can't figure out why it keeps setting bits in the hi order bytes
>inappropriately. If you will take a look at this code and give some
>suggestions they would be much appreciated.
<snipped down to 1st byte section>
>  movf da2_l, W
>  addwf da1_l, SAME
>  btfsc CARRY
>  incf da2_m, SAME
>  btfsc ZERO
>  incf da2_h, SAME
>  btfsc ZERO
>  incf da2_x, SAME

First I will assume SAME is defined as 1 and CARRY and ZERO are defined to
correctly reference the status bits. Look at the case of an input of all 0.
First addwf will results in clear carry, set zero. Skips the first incf, but
then the "btfsc ZERO" will not skip, incrementing the da2_h value.

A much faster and simpler approach is:
   movf da2_l,w        ; add first two bytes.
   addwf da1_1,f
   ; add second two bytes with carry in and carry out
   movf da2_m,w
   skpnc                ; this is a predefined macro in MPASM, skip if no
carry.
       incfsz da2_m,w   ; note use of "sz" version of incf, carry, zero not
changed.
       ; if above hits 0 then next add is skipped, carry is preserved!
   addwf da1_m,f        ; do next to lowest add.
   ; add third two bytes with carry in and carry out.
   movf da2_h,w
   skpnc
       incfsz da2_h,w
   addwf da1_h,f
   ; repeat again for fourth section.
   movf da2_x,w
   skpnc
       incfsz da2_x,w
   addwf da1_x,f

Chip Weller

1999\01\10@183310 by Regulus Berdin

picon face
Hi,

Your add routine may not work if the result of da2_l+da_1 has a carry
and da2_m is equal to 255 since it will become zero and the next
addition will be wrong.

Use the standard routine:

add32:
       movf    da2_l,w
       addwf   da1_l,f
       movf    da2_m,w
       skpnc
        incfsz da2_m,w
          addwf da1_m,f

       movf    da2_h,w
       skpnc
        incfsz da2_h,w
         addwf da1_h,f

regards,
Reggie

Keith Causey wrote:
{Quote hidden}

1999\01\10@230830 by Keith Causey

flavicon
face
Thanks Chip and Regulus, that worked. Now another question. How did you know
that MPLAB contained that macro? Is it possible to view the source for tant
macro? Are there other macros of the same utility in that same location?
                                   Thank You
                                   Keith Causey
{Original Message removed}

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