User Tools

Site Tools


base:8_bit_to_hexadecimal_conversion

This is an old revision of the document!


8 bit to hexadecimal conversion

by ABujok

This is another way to print a 8 bit integer value as a HEX value on a C64 Screen. The given integer must be loaded into the accu before calling the routine.

; Example:

	lda #$3F        ; load accu immediate with $3f or 63      
        jsr OUTHEX      ; print $3F
        rts             ; bye
; Syntax for DASM

BSOUT  = $ffd2	; Print character in accu

;**************************
; print Akku hex value
;**************************
OUTHEX	tax		; save value for low nibble
	and #$f0	; High nibble
	clc		; clear carry
	ror		; rotate one bit right
	ror		; rotate one bit right
	ror		; rotate one bit right
	ror		; rotate one bit right
	jsr NIB2HEX	; print nibble
	txa		; restore value
	and #$0f	; Low nibble
	jsr NIB2HEX	; print nibble
	rts


;*********************
;* Akku low Nibble to Hex
;*********************
NIB2HEX cmp #$0a	; Accu >= 10?
	bcs HEX		; Yes
DIGIT	clc		; Accu < 10
	adc #$30	; Accu + $30
	jmp OUT		; print
HEX	clc		;
	adc #$37	; Accu + $37
OUT	jmp BSOUT	; Print Accu (HEX nibble) and bye
base/8_bit_to_hexadecimal_conversion.1502378129.txt.gz · Last modified: 2017-08-10 17:15 by abujok