	.section	.text
	.global	strinsert
	.type	strinsert, @function
strinsert:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%esi			# Must preserve %esi and %edi
	pushl	%edi
	movl	12(%ebp), %esi		# source
	movzbl	(%esi), %ecx		# first byte of source (length)
	cmpl	16(%ebp), %ecx
	jb	end			# start > length
	movl	16(%ebp), %edx		# start
	subl	%edx, %ecx		# length = length - start
	movl	8(%ebp), %edi		# destination
	movb	%cl, (%edi)		# first byte of destination = length
	addl	$1, %edi		# destination = destination + 1
	addl	$1, %edx		# %edx = start + 1
	addl	%edx, %esi		# source = source + %edx
	addl	$1, %ecx		# length = length + 1
	cld				# Clear DF for up-memory write
	rep	movsb			# Blast the string into the buffer
end:
	popl	%edi			# Restore saved registers
	popl	%esi
	popl	%ebp
	ret
