include	clib.inc

PPROC	memmove, dst:DPTR, src:DPTR, cnt:word
	MPUSH	ds
	push	si
	push	di
	MLES	di,dst
	MLDS	si,src
	mov	cx,cnt
	mov	dx,es
	mov	ax,di
	cmp	ax,si
	ja	memmove_01
	cld
    memmove_00:
	shr	cx,1
	rep	movsw
	jc	memmove_c
    memmove_end:
	pop	di
	pop	si
	MPOP	ds
	ret
    memmove_c:
	movsb
	jmp	memmove_end
    memmove_01:
	std
	sub	cx,2
	add	si,cx
	add	di,cx
	add	cx,2
	jmp	memmove_00
PEND	memmove

	END
