[A83] Re: HL = A * 12 (fast)
[Prev][Next][Index][Thread]
[A83] Re: HL = A * 12 (fast)
This is such a simple algorithm, i've probably written it a hundred
times. If you guys want a challenge, how about you write a divide hl by 12
algorithm. I use that a lot for collision detection with my projects that
use 12x12 pixel tiles.
harper
At 03:13 PM 4/23/02 +0200, you wrote:
>I got ye beaten ;P Who does better?
>
>
>ld l,a
>add a,a ; *2
>add a,l ; *3
>ld l,a
>ld h,0
>add hl,hl ; *6
>add hl,hl ; *12
>
>
>
>----- Original Message -----
>From: "Darren" <qarnos@dingoblue.net.au>
>To: <assembly-83@lists.ticalc.org>
>Sent: Wednesday, April 24, 2002 7:35 AM
>Subject: [A83] HL = A * 12 (fast)
>
>
> >
> >
> > I wrote this little piece of code to calculate HL = A * 12. It seems to
> > be a bit faster than anything else I could find, so maybe some of you
> > could benefit from it, or prove me wrong! :)
> >
> > It takes 46 T-states, and destroys A:
> >
> > add a, a ; A * 2
> > ld l, a
> > add a, a ; A * 4
> > add a, l ; A * 6
> > ld l, a
> > sbc a, a
> > and 1
> > ld h, a
> > add hl, hl ; A * 12
> >
> >
> >
> >
> >
Follow-Ups:
References: