Compucolor.org – Virtual Media

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	FNDDIG - FIND A DIGIT IN INPUT BUFFER
;
;	IGNORES SPACES AND COMMAS
;
;	VALUES ON ENTRY:
;	   HL => INPUT BUFFER
;
;	RETURNS:
;	  <C>   SET IF DIGIT FOUND
;	   A  = DIGIT
;
;	DESTROYS:
;	   A REG.
;	   HL INCREMENTED TO POINT TO FIRST NON-SPACE
;

	EXTRN	DIGIT

	ENTRY	FNDDIG

FNDDIG:	INX	H
	MOV	A,M
	CPI	' '		;IGNORE SPACES
	JZ	FNDDIG
	CPI	','		;IGNORE COMMAS
	JZ	FNDDIG
	CALL	DIGIT		;<C> SET IF DIGIT
	RET

;..............................................................
;
;	GET AN UNSIGNED DECIMAL VALUE FROM INPUT BUFFER
;
;	VALUES ON ENTRY:
;	   HL => INPUT BUFFER
;
;	RETURNS:
;	   DECIMAL VALUE (0-255) IN A REGISTER.
;	   RETURNS A VALUE OF ZERO IF NO VALID DIGITS FOUND.
;
;	DESTROYS:
;	   A  REG.
;	   HL INCREMENTED TO POINT TO FIRST NON-DIGIT
;

	ENTRY	DECIN

DECIN:	PUSH	B
	MVI	B,0	;SETUP AS ZERO INITIALLY

DEC10:	CALL	DIGIT	;CHECK IF 0-9
	JNC	DEC20
	MOV	C,A	;KEEP NEW DIGIT
	MOV	A,B	;GET CURRENT SUM
	RLC		;MULTIPLY PARTIAL RESULT BY 2
	RLC		;   *4
	ADD	B	;   *5
	RLC		;   *10
	ADD	C	;ADD NEW DIGIT ...
	MOV	B,A	;... AND SAVE RESULT IN B
	INX	H	;POINT TO NEXT DIGIT
	JMP	DEC10	;REPEAT - EXCESS DIGITS FALL OUT TOP

DEC20:	MOV	A,B
	POP	B
	RET

	END