Re: 8bit binary to ASCII

From: Frank Kontros (frank_at_kontros.uzhgorod.ua)
Date: 2001-09-28 21:12:50

Hello ncoplin,

Wednesday, September 26, 2001, 3:24:59 AM, you wrote:

noc> Hi All,

noc> Does any one have a short assembly routine for converting an 8bit unsigned
noc> binary number (0-255) to ASCII?

What about that?


;---------------------------------------
; DISPLAY BL/BH AS DECIMAL STRING
; CODE LENGTH: 48 BYTES
;---------------------------------------

LEAD0    = $64   ;LEADING "0" FLAG

         *= $F65F

CONVRT   LDX #4       ;5 POWERS
         LDA #$FF     ;CLEAR LEAD0 FLAG
CV1      STA LEAD0
CV2      SEC          ;SUBTRACT POWER
         LDA BL       ;FROM BL/BH
         SBC NUMSLO,X
         TAY
         LDA BH
         SBC NUMSHI,X
         BCC CV4
         STY BL       ;SAVE RAMAINING
         STA BH       ;TO BL/BH
CV3      INC LEAD0
         BNE CV2
         BEQ CV3

CV4      LDA LEAD0    ;LEADING ZERO?
         BMI CV5      ;YES, SKIP
         ORA #$30     ;OR $30
         JSR $E716    ;AND PRINT OUT
         LDA #0       ;LEAD0 = 0
CV5      DEX          ;DECREMENT COUNTER
         BNE CV6      ;IF NOT 0, JUMP
         TXA          ;LEAD0 = X
CV6      BPL CV1      ;IF POSITIVE, JUMP
         RTS

NUMSLO   .BYTE $01,$0A,$64,$E8,$10
NUMSHI   .BYTE $00,$00,$00,$03,$27

It is 16 bit of course. I used it in my KERNAL patch for DIRECTORY listing routine.

-- 
Best regards,
 Frank                            mailto:frank@kontros.uzhgorod.ua



       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail 2.1.1.