Re: A83: Calculating this formula...


[Prev][Next][Index][Thread]

Re: A83: Calculating this formula...




"sla a" is 2 bytes, "add a,a" is 1 byte.  They do almost the same thing
functionality wise.  The difference is that with "sla" the carry flag will
be set to what bit 7 was, whereas with "add" it will be set if the result
overflowed.

Again, "srl" is two bytes, "rra" is one.  Rotating three times and masking
once takes five bytes, whereas shifting three times is six bytes.

So if you want to take up more space and have the code run slower, I suppose
they're better...

> I am pretty sure that sla a is still better than add a,a... and srl is
> shifting so there is no need to mask the upperbits...
>
> David Phillips wrote:
> >
> > If you're using the accumulator, you can save a byte and some cycles:
> >
> >  add a,a    ; a *2
> >
> > As for division, this will work, but remember that at the end you will
need
> > to mask off the upper bits:
> >
> >  rra      ; a / 2
> >  rra      ; a / 4
> >  rra      ; a / 8
> >  and %00011111        ; mask off top 3 bits since we shifted 3 times
> >
> > > also remember that a / 2 or a * 2 is much faster with shift operations
> > >
> > > ie. sla a = a*2
> > > srl a = a/2
>
> --
> Scott "_Wrath_" Dial
> wrath@calc.org
> ICQ#3608935
> Member of TCPA - tcpa.calc.org
> _____________________________________________
> NetZero - Defenders of the Free World
> Click here for FREE Internet Access and Email
> http://www.netzero.net/download/index.html
>
>




Follow-Ups: References: