Searching \ for 'Code challenge' 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=code+challenge
Search entire site for: 'Code challenge'.

Truncated match.
PICList Thread
'Code challenge'
2001\02\19@160722 by Don Hyde

flavicon
face
I need to add a 24-bit signed number to a 40-bit total, using a 16CXXX
processor.

What I've coded looks pretty messy by the time I've propagated the carries.
It seems really gross, and is slower than adding two 40-bit numbers!
Perhaps someone out there has thought about these and has it all worked out
already?

The 24-bit number is in AARGB2 thru AARGB0 (MSB)
The total is being accumulated in Xsum3_2 thru Xsum3_oflo2 (MSB)

; Accumulate sum of cubes

  movfw AARGB2
  addwf Xsum3_2,f

  movfw AARGB1
  skpnc
  incfsz   AARGB1,w
  addwf Xsum3_1,f

  movfw AARGB0
  skpnc
  incfsz   AARGB0,w
  addwf Xsum3_0,f

  clrf  temp
  btfsc AARGB0,7               ;check sign of addend
  decf  temp           ;temp has 0 or all ones

  movfw temp           ;temp has extended sign...
  skpnc
  incfsz temp,w
  addwf  Xsum3_oflo,f  ;add it to the total

  movfw temp           ;at least I reuse the extended sign
  skpnc
  incfsz temp,w
  addwf  Xsum3_oflo2,f

Don Hyde spam_OUTdhydeTakeThisOuTspamaxonn.com
Senior Software Engineer
Axonn Corporation http://www.axonn.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body


2001\02\19@173359 by Scott Dattalo

face
flavicon
face
On Mon, 19 Feb 2001, Don Hyde wrote:

{Quote hidden}

<snip>


    rlf    temp,w         ;pick up the carry
    addwf  Xsum3_oflo,f   ;and propogate to the upper 16bits
    skpnc                 ;C will only be set if W=1
     addwf Xsum3_oflo2,f  ;so we can add w to high 8.

Scott

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2001\02\19@182427 by Don Hyde

flavicon
face
Thanks.  That looks more like the way I thought it should look.  I just
couldn't see it.

{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2001\02\19@185520 by Bob Ammerman

picon face
----- Original Message -----
From: Don Hyde <KILLspamDonHKILLspamspamAXONN.COM>
To: <RemoveMEPICLISTTakeThisOuTspamMITVMA.MIT.EDU>
Sent: Monday, February 19, 2001 6:25 PM
Subject: Re: Code challenge


> Thanks.  That looks more like the way I thought it should look.  I just
> couldn't see it.
>
> > {Original Message removed}

2001\02\19@204018 by Scott Dattalo

face
flavicon
face
yes, Bob A., I ignored the sign. But here's something else that's nearly
efficient (in terms of cycles)

On Mon, 19 Feb 2001, Don Hyde wrote:

{Quote hidden}

; propogate the carry according to the sign of AARGB

    btfsc AARGB0,7
     goto prop_neg

 ; positive. Add 1 to high order bits if C is set
    incf    Xsum3_oflo2,f  ;precondition, assume high is inc'd
    skpnc
     incfsz Xsum3_oflo,f   ;First low byte
      decf  Xsum3_oflo2,f  ;assumption was wrong

    goto    done

prop_neg:
    movlw   0xff           ;sign extension
    skpc                   ;Dec high bytes only if no carry
     addwf  Xsum3_oflo,f
    skpc
     addwf  Xsum3_oflo2,f
done:


Still kind of yucky, but I think it's correct.
Scott

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body


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