User Tools

Site Tools


base:8_bit_to_hexadecimal_conversion

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
base:8_bit_to_hexadecimal_conversion [2017-08-20 00:07]
tww_ctr
base:8_bit_to_hexadecimal_conversion [2017-08-20 00:30]
tww_ctr
Line 67: Line 67:
  jsr NIB2HEX ; print nibble  jsr NIB2HEX ; print nibble
  rts  rts
- 
  
 ;********************* ;*********************
Line 76: Line 75:
         adc #$30 ; Accu < 10         adc #$30 ; Accu < 10
  jmp BSOUT       ; Print #$30 - #39  jmp BSOUT       ; Print #$30 - #39
-HEX sbc #$09 ; Accu >= 10, subtract #$09 to get "A" to "F"+HEX adc #$36 ; Accu >= 10, subtract #$09 to get "A" to "F" (CARRY always set here)
  jmp BSOUT ; Print Accu (HEX nibble) and bye  jmp BSOUT ; Print Accu (HEX nibble) and bye
 </code> </code>
  
-Alternatively, add #$36 (CARRY is setso effectively becomes #$37to get upper case characters in lower case modeAlso you can "branch alwaysafter adding #$30 to OUT to save a byte at the expense of 3 cycles.+Version not using KERNAL: 
 + 
 +<code> 
 +    // Dest.          = YREG:XREG 
 +    // Value to utput = ACC 
 +OUTHEX: 
 +    sty $fb 
 +    stx $fc 
 +    ldy #$00 
 +    pha 
 +    lsr 
 +    lsr 
 +    lsr 
 +    lsr 
 +    tax 
 +    lda tab,x 
 +    sta ($fb),
 +    iny 
 +    pla 
 +    and #$0f 
 +    tax 
 +    lda tab,x 
 +    sta ($fb),y 
 +    rts 
 + 
 +tab: 
 +    .text "0123456789abcdef" 
 +</code> 
base/8_bit_to_hexadecimal_conversion.txt · Last modified: 2017-08-20 00:30 by tww_ctr