include	clib.inc

PPROC	memxchg, dest:DPTR, src:DPTR, count:word
	MPUSH	ds
	push	si
	push	di
	MLDS	si,src
	MMOV	dx,ds
	MLES	di,dest
	mov	cx,count
	cld
    xchg_loop:
	mov	al,es:[di]
	movsb
	mov	[si-1],al
	dec	cx
	jnz	xchg_loop
	mov	ax,word ptr [dest]
	pop	di
	pop	si
	MPOP	ds
	ret
PEND	memxchg

	END
