>Suppose the addwf T2,F sets C and Z. Then, T4 will be incremented and
>the shift right 3 done below will cause the upper nibble of T3 to
>'flicker'.
Right on target, i realized it when i woke up this morning, thanks.
>It might be better to do something like this:
>
> movf INDF,W
> addwf T2,F
> rlf known_zero,W
> addwf T3,F
> rlf known_zero,W
> addwf T4,F
Seen before, but now i understand too...
That is a smart way to get the carry bit alone in a byte and add to the
higher byte and get both flags always correct. :)
Just need a register that is guaranteed zero.
Learned, must practise.
..will probably work for subtraction too.
{Quote hidden}>However, since you're doing something like:
> sum = sum + sample[i]
>
>where sum is 24 bits, and sample[i] is 16 bits, it might be better to do
>this:
>
> movf INDF,W ;Get low byte,
> incf FSR,F
>
> addwf T2,F
> movf INDF,W
>
> skpnc
> incfsz INDF,W
> addwf T3,F
>
> skpnc
> incf T4,F
>
> incf FSR,F ;Point to next variable low byte
> ...
>
>This way you only have to deal with the carry once. (I think this is
>right, but it's not tested.)
Should work. I learned that movf-skpnc-incfsz-addwf -trick last week, so i
have not updated this routine yet.
>Should I add comments?
If anyone is interested, I posted "Re: 32 Bit Addition (commented)" three
days ago, and then Dimitry replied to that.
{Quote hidden}>for the shift right 3, you might want to just unroll the loop:
>
> rrf T4,F
> rrf T3,F
> rrf T2,F
>
> rrf T4,W
> andlw 00011111b
> movwf T4
> rrf T3,F
> rrf T2,F
>
> rrf T4,F
> rrf T3,F
> rrf T2,F
>
>It's 3 instructions longer, but twice as fast (11 cycles vs 23 cycles)
I think the andlw trick is a nice way to not need to use clear carry before
each shift sequence. :)
Thinking about it i do not need to clear incoming carry to T4 at all
anyway, since it is trasched, and the whole result is only in T3:T2
It then becomes a childs play:
rrf T4,F
rrf T3,F
rrf T2,F
rrf T4,F
rrf T3,F
rrf T2,F
rrf T4,F
rrf T3,F
rrf T2,F
...almost ridiculous. 9 instr, 9 cyc.
And i think i will unroll the add to straight inline using the
known-zero-trick. I still have lot of code space and this filter is one of
the most often run routines.
And if time I'll see what i can do to boost the
findinjectposition-shift-inject in MOMA. Any ideas?
>Scott
Thanks, Scott
Thank you also, Mike, for your corrections
Stefan, have you got the filter working now?
/Morgan
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 .....mrtKILLspam
.....iname.com
___________________________________________________________