NewsProductsSprinterSupportDownloadSprinter ForumAbout usLinksSite map Russian site
Support
 Updates | Knowledge base | Manuals | Resellers | Warranties | Feedback

Knowledge Base

[ Back ] [ Index ] [ Categories ] [ Next ]

Q10024. Routine (Byte2Hex) of preparing an 8 bit number to be printed in HEX form.

More information

Converts a 1-byte value to four hexadecimal characters. All values are considered positive.

Assembler

Any assembler.

Input

(SP+4) -> Number to convert (in LSB, MSB is ignored)
(SP+2) -> Two-byte ASCII buffer start address
(SP+0) -> Normal return address

Output

ASCII buffer is filled with the converted number
A : Ascii code of lowest nibble of converted number
D : Ignored MSB of number to convert
E : Number to convert
HL: Pointer to last char in buffer

Routine

Byte2Hex:	POP	HL		;Get ret address temporarily
		POP	DE		;Get Buffer address
		LD	(B2HBuf),DE	;Save Buffer address
		POP	DE		;Get Number
		PUSH	HL		;Push return value
		LD	HL,(B2HBuf)	;Make HL point to buffer
		LD	A,E		;Number to A (H=0, and ignored)
		RRCA			;Get hi-nibble of A into lo-nibble
		RRCA
		RRCA
		RRCA
		AND	0Fh		;Isolate lo-nibble
		ADD	A,"0"		;Add ASCII for zero
		CP	3Ah		;Greater than "9"?
		JR	C,B2HBig1	;Jump if so
		ADD	A,07h		;Add ASCII difference to "A"
B2HBig1:	LD	(HL),A		;Save char to buffer
		INC	HL		;Point to next char in buffer
		LD	A,E		;Rretrieve number
		AND	0Fh		;Isolate lo-nibble
		ADD	A,"0"		;Add ASCII for "0"
		CP	3Ah		;Greater than "9"?
		JR	C,B2HBig2	;Jump if so
		ADD	A,07h		;Add ASCII difference to "A"
B2HBig2:	LD	(HL),A		;Save char to buffer
		RET			;Done.

B2HBuf:		DW	0000h

Added by

Marcelo Lopez

14 May 2003.
PETERS PLUS LTD.

[ Back ] [ Index ] [ Categories ] [ Next ]