> > > I've converted a 16-bit addition function, and I'm sure I can do the
> > > subtract function as well. The tough ones are multiply and divide.
> > >
> > > Example: 16-bit addition from
http://www.myke.com/
> > >
> > > movf acc_b_hi,w
> > > addwf acc_a_hi,f ; add most significant byte
> > > movf acc_b,w
> > > addwf acc_a,f ; add least significant byte
> > > btfsc status,c
> > > incf acc_a_hi ; if carry, increment MSB
> > > retlw 0
> > >
> > > That requires four bytes of register file and seven instructions.
> > > Now, re-working it to use a data stack makes it look like this;
> > > (the parenthetical stuff is forth-like stack comments, the ^ tilde
> > > indicates where the stack pointer FSR has been moved to)
> > >
> > > ;; ( lsb1 msb1 lsb2 msb2 -- lsb3 msb3 )
> > >
> > > movf indf,w ; msb2
> > > incf fsr,f ; ( lsb1 msb1 lsb2 ^ msb2 )
> > > incf fsr,f ; ( lsb1 msb1 ^ lsb2 msb2 )
> > > addwf indf,f ; msb3 = msb1 + msb2
> > > decf fsr,f ; ( lsb1 msb3 lsb2 ^ msb2 )
> > > movf indf,w ; lsb2
> > > incf fsr,f ; ( lsb1 msb3 ^ lsb2 msb2 )
> > > incf fsr,f ; ( lsb1 ^ msb3 lsb2 msb2 )
> > > addwf indf,f ; lsb3 = lsb1 + lsb2
> > > decf fsr,f ; ( lsb3 msb3 ^ lsb2 msb2 )
> > > btfsc status,c ; carry?
> > > incf indf,f ; msb1
> > > retlw 0 ; ( lsb3 msb3 )
> > >
> > > Now 13 instructions and no register file usage apart from the data
> > > stack. I have more instruction space spare than register file.
> > >
> > > The multiply function I have is also from Myke's site. 16-bit inputs,
> > > 16-bit output.
> > >
> > > The division function I have is from Application Note 526.
> > > Two 16-bit inputs, two 16-bit outputs, result and remainder.
> > >
> > > --
> > > James Cameron
.....quozlKILLspam
@spam@us.netrek.org http://quozl.us.netrek.org/
> >
>
>