Searching \ for '[PIC]: Help generating a 16 bit number' 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/microchip/devices.htm?key=pic
Search entire site for: 'Help generating a 16 bit number'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Help generating a 16 bit number'
2000\07\23@163037 by Jason

flavicon
face
Hi everyone,

I need to add ten numbers together and store the result in two locations
N_hi and N_lo(a 16 bit number).
I am sure there must be an easy way to do this.
Can anyone please provide some code to achieve this.

Many thanks

Jason

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2000\07\23@195534 by James Cameron

flavicon
face
G'day Jason,

For each of the ten numbers, add them into the W register using an
ADDWF instruction, but check the C flag of STATUS after each addition.
If the C flag is set, increment the n_hi register.

       clrf    n_hi
       clrw

       addwf   n1, w
       skpnc
       incf    n_hi

       addwf   n2, w
       skpnc
       incf    n_hi

       ...

       movwf   n_lo

Or if the numbers are in a series of locations, use FSR and INDF to
loop through them.

--
James Cameron    spam_OUTquozlTakeThisOuTspamus.netrek.org     http://quozl.netrek.org/

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2000\07\24@073034 by Kevin Blain

flavicon
face
;    Multi-byte add routine.
;    requires number of registers, start register address
;    affects w, FSR / INDF and status
;    result in N_hi and N_lo

   movlw    number_of_registers
   movwf    counter    ; used to count how many successive registers to add
together
   movlw    start_register_address
   movwf    fsr    ; used FSR and INDF to address successive memory
locations
   clrf    N_hi        ; start with zero in N_hi and N_lo
   clrf    N_lo
loop:
   movf    INDF,w    ; get latest byte to add in
   addwf    N_lo,f    ; add to low order byte
   skpnc        ; test carry, if set, increment the hi order byte
   incf    N_hi,f
   incf    FSR,f
   decfsz    counter    ; if counter is >1 then repeat loop
   goto    loop

; counter is zero, N_hi and N_lo contain reasult, w has changes tolast
value, FSR has last pointer
; total routine size 13 words.
; execution time 4+ (10 x number of resisters) cycles

Hope this helps,
Regards, Kevin
{Original Message removed}

2000\07\24@103625 by jamesnewton

face picon face
homework?

---
James Newton .....jamesnewtonKILLspamspam@spam@geocities.com 1-619-652-0593


-----Original Message-----
From: pic microcontroller discussion list
[PICLISTspamKILLspamMITVMA.MIT.EDU]On Behalf Of Jason
Sent: Saturday, July 22, 2000 13:38
To: .....PICLISTKILLspamspam.....MITVMA.MIT.EDU
Subject: [PIC]: Help generating a 16 bit number


Hi everyone,

I need to add ten numbers together and store the result in two locations
N_hi and N_lo(a 16 bit number).
I am sure there must be an easy way to do this.
Can anyone please provide some code to achieve this.

Many thanks

Jason

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu>

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