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 revisionPrevious revision
Next revision
Previous revision
base:8_bit_to_hexadecimal_conversion [2017-08-12 13:24] – Slight optimization. tww_ctrbase:8_bit_to_hexadecimal_conversion [2017-08-20 00:30] (current) tww_ctr
Line 58: Line 58:
 ;************************** ;**************************
 OUTHEX tax ; save value for low nibble OUTHEX tax ; save value for low nibble
- and #$f0 ; High nibble +        lsr             ; ignore CARRY and shift hi nybble to lonybble pos. 
-        lsr             ; ignore CARRY! + lsr ;  
- ror rotate one bit right + lsr ;  
- ror rotate one bit right + lsr ;  
- ror rotate one bit right -> CARRY must be clear when calling NIB2HEX! + jsr NIB2HEX ; print nibble
- jsr NIB2HEX ; print nibble - CARRY always clear when exiting the subroutine+
  txa ; restore value  txa ; restore value
  and #$0f ; Low nibble  and #$0f ; Low nibble
  jsr NIB2HEX ; print nibble  jsr NIB2HEX ; print nibble
  rts  rts
- 
  
 ;********************* ;*********************
Line 77: 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.1502537067.txt.gz · Last modified: 2017-08-12 13:24 by tww_ctr