	.section	.text
	.global	memmove
	.global	__aeabi_memmove
	.type	memmove, @function
memmove:
__aeabi_memmove:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%esi			# Must preserve %esi and %edi
	pushl	%edi
	movl	16(%ebp), %ecx		# number
	movl	12(%ebp), %esi		# source
	movl	8(%ebp), %edi		# destination
	cmpl	%edi, %esi		# source < destination
	jnb	is_greater

	# address = number - 1
	addl	%ecx, %esi		# source = source + number
	addl	%ecx, %edi		# destination = destination + number
	subl	$1, %esi		# source = source - 1
	subl	$1, %edi		# destination = destination - 1

	std				# Set DF flag for down-memory write
	rep	movsb			# Blast the string into the buffer
	jmp	end
is_greater:
	cld				# Clear DF flag for up-memory write
	rep	movsb			# Blast the string into the buffer
end:
	popl	%edi			# Restore saved registers
	popl	%esi
	popl	%ebp
	ret
