; Print a byte as hexadecimal 
; note how to get lower 4 and upper 4 bits
; JDN / AAU

	JMP start
vidmem:  db 232
val:    db 0x3C
start:
	PUSH [vidmem]
	PUSH [val]

	CALL printhexbyte

        HLT             ; Stop execution
        ; video loc  +5
	; byte2print +4
	; ret adr    +3
	; pushed A   +2
	; pushed B   +1
	; SP
printhexbyte:			; print(C:*from, D:*to)
	PUSH A
	PUSH B
	MOV A,[SP+4]
	MOV B, [SP+5] ; where to print
	PUSH A
	SHR A, 4
	CALL printnible
	POP A
	AND A,0x0f
	INC B
	CALL printnible
	POP A
	POP B
	RET

printnible:
	CMP A,9  ; below or eq 9 then its 0-9
	JA a2f   ; If above then its a-f
	ADD A,0x30  ; ascii 0-9
	JMP doprt
a2f:	SUB A,0x0a  ; a-f -> 0-5
	ADD A,0x41  ; ascii a-f
doprt: 	MOV [B], A
	RET
