Compucolor.org – Virtual Media

Listing of file='DECOUT.MAC;03' on disk='vmedia/asm_utility_routines-sideA-sector.ccvf'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	CONVERT A BYTE TO THE ASCII FOR THE DECIMAL NUMBER
;
;	VALUES ON ENTRY:
;	   A  =  BYTE TO CONVERT
;	   HL => BUFFER FOR RESULT (3 BYTES LONG)
;
;	RETURNS:
;	   RESULT IS IN BUFFER POINTED TO BY HL
;
;	DESTROYS:
;	   A REGISTER
;	   HL INCREMENTED TO END OF BUFFER
;

	ENTRY	DECOUT

DECOUT:	PUSH	D	;SAVE REGISTERS
	PUSH	B
	LXI	D,0	;INITIALISE COUNTERS
HNDRED:	SUI	100
	JC	ADD100
	INR	E	;COUNT THE HUNDREDS
	JMP	HNDRED
ADD100:	ADI	100	;GONE ONE HUNDRED TOO FAR
TENS:	SUI	10
	JC	UNITS
	INR	D	;COUNT THE TENS
	JMP	TENS
UNITS:	ADI	10+'0'	;GONE 10 TOO FAR, ALSO CONVERT TO ASCII
	MOV	C,A
	MOV	A,E	;STORE DIGITS IN CORRECT ORDER
	ADI	'0'	;CONVERT TO ASCII
	MOV	M,A
	INX	H
	MOV	A,D
	ADI	'0'
	MOV	M,A
	INX	H
	MOV	M,C
	POP	B	;RESTORE REGISTERS
	POP	D
	RET

	END