	.section	.text
	.global	div
div:
	str	fp, [sp, #-4]!
	mov	fp, sp
	sub	sp, sp, #8	@ Allocate space
	str	r0, [fp, #-8]	@ Store address of record
	mov	r0, #0		@ clear r0 to accumulate result
	mov	r3, #1		@ set bit 0 in r3, for shifting
div.start:
	cmp	r2, r1		@ den < num
	movls	r2, r2, lsl #1
	movls	r3, r3, lsl #1
	bls	div.start
div.next:
	cmp	r1, r2		@ carry set if r1 > r2
	subcs	r1, r1, r2	@ subtract if result would be positive
	addcs	r0, r0, r3	@ add current bit in r3 to accumulating answer
	movs	r3, r3, lsr #1
	movcc	r2, r2, lsr #1
	bcc	div.next
	ldr	r3, [fp, #-8]	@ Load address of record
	stm	r3, {r0, r1}	@ Save values to record
	mov	r0, r3		@ Return address of record
	mov	sp, fp		@ Deallocate space
	ldr	fp, [sp], #4
	mov	pc, lr
