Page 1 of 1

Re: 8bit to ASCII

Posted: Sat Dec 08, 2018 12:01 am
by Einar Saukas
Ast A. Moore wrote: Fri Dec 07, 2018 6:55 pm Yeah, so in Z80 speak that would be:

Code: Select all

	ld hl,$3a2f
	scf
l1	inc l
	sbc 100
	jr nc,l1
l2	dec h
	adc a,10
	jp m,l2	
	adc a,$2f
	ld (string),hl
	ld (string+2),a
	ret
string	defm "---"
Nice!!!

Even better:

Code: Select all

        ld hl,256*58+47
p1:     inc l
        sub 100
        jr nc,p1
p2:     dec h
        add a,10
        jr nc,p2
        ld (string),hl
        add a,48
        ld (string+2),a
        ret
string: db '000'

Re: 8bit to ASCII

Posted: Sat Dec 08, 2018 12:08 am
by Ast A. Moore
Okay, grandma can hang on to her pearls for another day. I figured it out:

Code: Select all

	ld hl,$3a2f
l1	inc l
	sub 100
	jr nc,l1
l2	dec h
	add a,10
	jp m,l2	
	adc a,$30
	ld (string),hl
	ld (string+2),a
	ret
string	defm "---"
Faster, smaller.

EDIT: Ha! Einar beat me to it. His is even one byte smaller (but mine is marginally faster). :P Great minds . . .

Re: 8bit to ASCII

Posted: Sat Dec 08, 2018 12:25 am
by Einar Saukas
Ast A. Moore wrote: Sat Dec 08, 2018 12:08 am EDIT: Ha! Einar beat me to it. His is even one byte smaller (but mine is marginally faster).
It depends... If middle digit is 9, then using JP is actually slower!

Ast A. Moore wrote: Sat Dec 08, 2018 12:08 am Great minds . . .
You did most of the work anyway :)

Re: 8bit to ASCII

Posted: Sat Dec 08, 2018 10:01 am
by g0blinish
There are some ways to convert:
http://z80-heaven.wikidot.com/math#toc21

as backside you got mirrored number xD