# RE: Assy question - I challenge you to do better!

From: Christopher Phillips (cphillips_at_reflectionsinteractive.com)
Date: 2001-03-19 11:35:33

```I'm jumping in mid thread here, 'cos I only just got
around to subscribing (Hi Marko, hi Steve, and anyone
who still remembers Christopher Jam), so thump me if
I'm re-covering old ground ;-)

I remember this for one nybble:

; input: a in 0..15
; output: petscii hex representation of a
; 0..9 -> \$30..\$39
; A..F -> \$41..\$46

cmp#\$0a
bcc \$1

; (7*10+6*8)/16 = 7.375 cycles

so we can fairly naively extrapolate to the following:

; input: a contains num
; output: x,a contain the ascii hex representation of num

tay
lsr a
lsr a
lsr a
lsr a

cmp#\$0a
bcc \$1

tax
tya
and#\$30

cmp#\$0a
bcc \$2

;  10+7.375+6+7.375 = 30.75 cycles

... plus how ever many cycles you need to load/store the values.

This should be beatable, cos I haven't really put that much
thought into it, but I should get back to work now :-)

Christopher.

> -----Original Message-----
> From: Professor Dredd [mailto:profdredd@yahoo.com]
> Sent: 17 March 2001 11:01
> To: cbm-hackers@dot.tml.hut.fi
> Subject: Re: Assy question - I challenge you to do better!
>
>
> I know I didn't disqualify table use in my challenge
> so I suppose thats the fastest possible way, eh Steve?
>  ;-)
>
> Indeed the cycle count is as low as possible!
> Howevever, your 2-table3 algo uses just over 2 pages
> of memory!  :-O
>
> If I were going to use tables, I might be more
> inclined to do something like:
>
> LDA BYTE
> LSR
> LSR
> LSR
> LSR
> TAX
> LDA TABLE,X
> STA \$FB
> LDA BYTE
> AND #\$0F
> TAX
> LDA TABLE,X
> STA \$FC
> RTS
> TABEL TXT '0123456789ABCDEF'
>
> I THINK that should do it, (Spiro?)
>
> Does anyone know a NON-TABLE algo to do the same thing
> with lowest possible cycle count?
> --- Steve Judd <sjudd@swcp.com> wrote:
> > On Fri, 16 Mar 2001, Professor Dredd wrote:
> >
> > > For some time I've wondered if there were a faster
> > way
> > > to convert binary to ASCII coded hex. I even
> > played
> > > with some BCD numbers before I understood the
> > Decimal
> > > mode. If you can code an algorithm with the lowest
> > > possible cycle count to process in 1-byte chunks,
> > > please do  :-)
> >
> > LDX num
> > LDA highnyb,X
> > LDY lownyb,X
> >
> > -S
> >
> > -
> > This message was sent through the cbm-hackers
> > mailing list.
> > To unsubscribe: echo unsubscribe | mail
> cbm-hackers-request@dot.tml.hut.fi.
>
>
> =====
> Get a FREE 6Mb webmail box from go6502! -
> http://www.geocities.com/profdredd
>
> As low as 2.99% Intro APR from NextCard! -
> http://www.nextcard.com/index6.html?ref=aff0074521
>
> PayPal is the FAST FREE and SECURE way to send money! -
> https://secure.paypal.x.com/refer/pal=profdredd%40yahoo.com
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
> -
> This message was sent through the cbm-hackers mailing list.
> To unsubscribe: echo unsubscribe | mail
> cbm-hackers-request@dot.tml.hut.fi.
>
-Virus scanned and cleared ok
-
This message was sent through the cbm-hackers mailing list.
To unsubscribe: echo unsubscribe | mail cbm-hackers-request@dot.tml.hut.fi.
```

Archive generated by hypermail 2.1.1.