> -----Original Message----- > From: ncoplin@orbeng.com [mailto:ncoplin@orbeng.com] > Sent: 26 September 2001 11:27 > To: cbm-hackers@cling.gu.se > Subject: RE: 8bit binary to ASCII > > > Thanks Guys, > There's obviously several ways to do it, will check through > the merits of > each. > No worries. And here's a somewhat less buggy version of the code I sent earlier today.. (removed duplicate lables, delete a CLC that shouldn't have been there). It's marginally faster and shorter as well (inx instead of inc buf+1) .convertbytetoasciidecimal ;enter with number in A ;exit with null terminated 3 character string in buf ldx#32 ;default first char to space.. stx buf+1 ;and clear low 5 bits of buf+1 cmp#100 bcc writefirstdigit sbc#100 ldx#'1' cmp#100 bcc writefirstdigit sbc#100 ldx#'2' .writefirstdigit stx buf ; A now contains N=0..99 ; save it on the stack, then ; compute ((N/2*3*17)+40)/256 ; to get the high digit php lsr a sta Non2 asl a ; also clears carry :-) adc Non2 ;A now contains N/2*3 sta Nby2on3 asl a rol buf+1 asl a rol buf+1 asl a rol buf+1 asl a rol buf+1 ldx buf+1 ; X & A now contain hi & lo bytes of N*2/3*16 adc Nby2on3 bcc $1 inx ; X & A now contain hi & lo bytes of N*2/3*17 $1: adc#39 ;doesnt matter if this adds 39 or 40 bcc $2 inx $2: clc txa adc#'0' ; and leave carry clear sta buf+1 plp adc asczerotakeXtimes10,x sta buf+2 rts .Non2 ;never need both of these at once. .Nby2on3 byte 0 .buf byte 0,0,0,0 .asczerotakeXtimes10 byte '0'- 0, '0'-10, '0'-20, '0'-30, '0'-40 byte '0'-50, '0'-60, '0'-70, '0'-80, '0'-90 -Virus scanned and cleared ok Message was sent through the cbm-hackers mailing list
Archive generated by hypermail 2.1.1.