include	clib.inc
include	stdlib.inc

PPROC	strtol, string:DPTR	; '100h'	- hex
	push	di		; 'f3 22'	- hex
	MLES	di,string	; '128'		- long
	mov	dx,di		; '128 C:\file'	- long
	mov	ah,'9'
    strtol_loop:
	mov	al,es:[di]
	inc	di
	jz	strtol_null
	test	al,al
	jz	strtol_long
	cmp	al,' '
	je	strtol_long
	cmp	al,ah
	jbe	strtol_loop
	MPUSH	es
	push	dx
	call	xtol
    strtol_end:
	pop	di
	ret
    strtol_long:
	MPUSH	es
	push	dx
	call	atol
	jmp	strtol_end
    strtol_null:
	xor	ax,ax
	cwd
	jmp	strtol_end
PEND	strtol

	END
