Exact match. Not showing close matches.
PICList
Thread
'[PIC]: Help generating a 16 bit number'
2000\07\23@163037
by
Jason
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
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_OUTquozlTakeThisOuT
us.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
; 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
More... (looser matching)
- Last day of these posts
- In 2000
, 2001 only
- Today
- New search...