

addi	r2, r0, 4		//size of matrix
addi	r7, r0, 20		//base address of A
addi	r8, r0, 100		//base address of B
addi	r9, r0, 120		//base address of C
		
addi	r3, r0, 0		//init i=0
begina:	
bge	r3, r2, endloopa	//if i>=box goto loopa
	
addi	r4, r0, 0		//j=0
beginb:	
bge	r4, r2, endloopb	//if j>=box goto loopb

	
mult	r3, r2			//calculate offset of [i,j]
add	r10, r30, r4

add	r11, r7, r10		//base address + index = memlocation of A[i,j]
st_d	0(r11), r3		//store i into A[i,j]

add	r12, r8, r10		//base address + index = mem location of B[i,j]
st_d	0(r12), r4		//store j into B[i,j]

addi	r4, r4, 1		//j++
j	beginb			//start loopb again
endloopb:	
	
addi	r3, r3, 1		//i++
j	begina			//start loopa again

endloopa:	
		
addi	r3, r0, 0		//i=0
loop1:
bge	r3, r2, endloop1	//if i>= box goto endloop1
	
addi	r4, r0, 0		//j=0
loop2:
bge	r4, r2, endloop2	//if j>= box goto endloop2
	
addi	r6, r0, 0		//var = 0
		
addi	r5, r0, 0		//temp = 0
loop3:
bge	r5, r2, endloop3	//if temp >= box goto endloop3
	
mult	r3, r2
add	r13, r30, r5
add	r14, r13, r7
ld_d	r15, 0(r14)		//r15 = A[i, temp]

mult	r5, r2
add	r16, r30, r4
add	r17, r16, r8
ld_d	r18, 0(r17)		//r18 = B[temp, j]

mult	r15, r18
add	r6, r6, r30		//var = var + (A[] * B[])
	
addi	r5, r5, 1
j	loop3
endloop3:

mult	r3, r2			//r30 = i*box find row offset
add	r20, r30, r4		//r20 = r30+j find col offset
add	r21, r20, r9		//r21 = r20 + r9 add offset to base addr
st_d	0(r21), r6		//C[i,j]=var
	
addi	r4, r4, 1
j	loop2
endloop2:

addi	r3, r3, 1
j	loop1
endloop1:

exit







