//Assign3_1.s
//Average of 10 numbers
.text
.global _start
_start:
	LDR r8, =mydata
	LDR r4, =0x40002000
	MOV r1, #10  //counter
	MOV r3, #0 //Sum (
again:
	LDR r2, [r8]
	ADD r3, r3, r2
	ADD r8, r8, #4
	SUBS r1, r1, #1
	BNE again
	
// Now r5 holds the sum
	MOV r5, r3
	MOV r6, #10  //denominator
	
	BL div
	
	STR r0, [r4] //Quotient
	ADD r4, r4, #4
	STR r5, [r4]  //remainder (unncessary)

stop:
	B stop
	//DIV subroutine
div:
	//repeated subtraction of the
	//denominator (r6) from the numerator (r5)
	// Quotient  as answer in r0
	//Remainder in r5 (numerator)
	//r0 must be cleared 
	MOV r0, #0
loop:
	CMP r5,r6
	BLO nomore
	SUB r5,r5,r6
	ADD r0, r0, #1
	B loop
nomore:
	BX lr
		

.data
mydata:
	.word 57, 75, 35, 54, 99, 77, 81, 90, 18, 39
	
.end