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

Knowledge Base

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

Q10025. Routine (Byte2Ascii) of preparing an 8 bit number to be printed in decimal form.

More information

Routine converts an 1-byte number to ASCII characters. Leading zeroes are replaced by spaces. All values are considered positive.

Assembler

Any assembler.

Input

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

Output

ASCII buffer is filled with converted number
A : Ascii code of LSB
C : Ascii code of mid-significant digit (or space, if it was zero)
HL: Pointer to last char in buffer

Routine

Byte2Ascii:	POP	BC		;Fetch ret address temporarily
		POP	HL		;Fetch ASCII buffer address
		POP	DE		;Fetch nmber to convert in E
		PUSH	BC		;Push back ret address
		LD	A,E		;Get number to convert in A
		LD	C,"0"-1		;Prepare character
B2A_3:		INC	C		;Inc char
		SUB	100		;Subtract 100 from A
		JR	NC,B2A_3	;Keep looping until negative
		ADD	A,100		;Restore positive value
		LD	E,A		;Save value temporarily
		LD	A,C		;Hundreds char to A
		CP	"0"		;Is zero?
		JR	NZ,B2A_Hundreds	;Jump if not
		LD	C," "		;Preset to put a space if Hundreds=0
B2A_Hundreds:	LD	(HL),C		;Save hundreds char
		LD	A,E		;Retrieve old value
		INC	HL		;Point to next char
		LD	C,"0"-1		;Prepare character
B2A_2:		INC	C		;Inc char
		SUB	10		;Subtract 10 from A
		JR	NC,B2A_2	;Keep looping until negative
		ADD	A,"0"+10	;Restore positive value (and ASCII)
		LD	E,A		;Save char briefly
		LD	A,C		;Tens char to A
		CP	"0"		;Is zero?
                JR	NZ,B2A_Tens	;Jump if not
		LD	C," "		;Change char to be a space
		LD	A,E		;Retrieve last char
B2A_Tens:	LD	(HL),C		;Save tens char
		INC	HL		;Point to next char
		LD	(HL),A		;Save units char (don't check for 0)
		RET			;Done 

Added by

Marcelo Lopez

14 May 2003.
PETERS PLUS LTD.

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