Truncated match.
PICList
Thread
'Bug in posted MOMA code?? - fixed'
1998\11\10@005817
by
Morgan Olsson
|
Good morning.
Amazing what a good night sleep can remove bugs from your brain.
In the case of adding low byte gave zero but no carry as result, that Z
flag would cause highest byte to increment, as middle byte inc was skipped.
Fixed now below.
Should work, not compiled yet.
I'm sorry for thoose who tested MOMA with the erroneous sum routine...
Regards
/Morgan
Sum16: ;commented in english
;Summs a interval of 2-byte variables to 3-byte T4:T3:T2
;MSB at adress of LSB +1.
;Before call, state in W the total number of 2byte variables to sum.
;And set FSR to point to the low byte of first variabe to sum.
;(FSR may point in bank 0 or 1 regardless of back select :) )
;FSR get incremented by two for each variable summed
movwf T1 ;store number of variables to temp reg T1
movlw 4 ;Preload destination with 000004h
movwf T2 ;(New; for correct rounding in this application
clrf T3 ;where we sum 8 variables;
clrf T4 ;For normal SUM use we clear all T4:T3:T2)
Sum16loop:
movf INDF,W ;Get low byte,
addwf T2,F ;and add to low byte result
ifcc ;If carry clear, <<<<<<<< Changed
goto Sum16lhigh; go right on with high byte <<<<<<<<< New
incf T3,F ;If carry: inc middle byte result;
ifzs ;If that wrapped to Zero,
incf T4,F ; inc high byte result too.
Sum16lhigh:
incf FSR,F ;Point to MSB in,
movf INDF,W ;get it,
addwf T3,F ;and add to middle byte result
ifcs ;If carry,
incf T4,F ; inc high byte result
incf FSR,F ;Point to next variable low byte
decfsz T1,F ;Decrease counter for variables to add,
goto Sum16loop;if not done add next variable
return ;the sum +4 is now in T4:T3:T2
Morgan Olsson ph +46(0)414 70741
MORGANS REGLERTEKNIK fax +46(0)414 70331
H€LLEKS (in A-Z letters: "HALLEKAS")
SE-277 35 KIVIK, SWEDEN spam_OUTmrtTakeThisOuT
iname.com
___________________________________________________________
1998\11\10@065618
by
Stefan Sczekalla-Waldschmidt
Hi,
Interesting how many minds will come to similar solutions ...
I should have read all messages first before writing answers already
given :)
Kind regards
Stefan Sczekalla-Waldschmidt
.....sswKILLspam
@spam@oikossw.de
More... (looser matching)
- Last day of these posts
- In 1998
, 1999 only
- Today
- New search...