@ r0 = destination
@ r1 = source
	.section	.text
	.global	strcat
	.syntax	divided
strcat:
	str	fp, [sp, #-4]!		@ Preserve the frame pointer
	mov	fp, sp
	sub	sp, sp, #8		@ Allocate space
	ldr	r3, [r1, #-4]		@ Length of source
	ldr	r2, [r0, #-4]		@ Length of destination
	str	r3, [fp, #-8]		@ Save length of source on the stack
	add	r3, r3, r2		@ Calculate the length of string
	str	r3, [r0, #-4]		@ Set length of destination
	add	r0, r0, r2		@ Skip to the end of destination
	ldrb	r2, [r1]		@ r2 = source, dereferenced
	b	strcat.loop
strcat.copy:
	ldrb	r2, [r1]		@ r2 = source, dereferenced
	strb	r2, [r0]		@ destination, dereferenced = r2
	ldr	r2, [fp, #-8]
	sub	r2, r2, #1
	str	r2, [fp, #-8]		@ length = length - 1
	add	r1, r1, #1		@ source = source + 1
	add	r0, r0, #1		@ destination = destination + 1
strcat.loop:
	ldr	r2, [fp, #-8]
	cmp	r2, #0
	bne	strcat.copy		@ length <> 0
	mov	sp, fp			@ Deallocate space
	ldr	fp, [sp], #4		@ Restore the frame pointer
	mov	pc, lr			@ Return
