Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.
Could you calculate how many memory quot;dataquot; words and bytes are used, and how are they accessed by the program (e.g. random, in order, every...
Could you calculate how many memory "data" words and bytes are used, and how are they accessed by the program (e.g. random, in order, every other one,
etc)?
# void mmult(double x[][], double y[][], double z[][], int n)
# // Inputs:x,y,z are n X n matrices.
# // Side-effect: z is modified, so that z = x * y
# {
# int i,j;
# for (i=0; i != n; i++)
# for (j=0; j != n; j++)
# z[i][j] = 0.0;
# for (k=0; k != n; k++)
# z[i][j] = z[i][j] + x[i][k] * y[k][j];
# }
.text
.globl __start
__start:
sub$sp,$sp,4
sw$ra,0($sp)
la$a0,A
la$a1,B
la$a2,C
addi$a3,$zero,5
jalmmult
ori $v0,$0,10 # end program gracefully
syscall
jr $ra # return
nop
.data
.align2
A: .word -7040,1913,-8071,4711,-6622
.word -3276,-5345,-6448,-3768,1603
.word 5137,2481,-6442,5636,5116
.word -6935,-21,-2177,3940,5154
.word -2384,-3531,-4266,5343,-6727
B:.word 2192,-4804,-7718,-6279,-3812
.word -7961,897,-8043,4031,7692
.word -485,6214,1580,5076,-5181
.word 6330,948,1787,4018,-3278
.word -6324,4134,6864,-2668,-1455
C: .word 0,0,0,0,0
.word 0,0,0,0,0
.word 0,0,0,0,0
.word 0,0,0,0,0
.word 0,0,0,0,0
# matrix multiplication.
# leaf procedure
# inputs in $a0 = x, $a1 = y, $a2 = z, $a3 = n
# assume that n > 0
.text
mmult:
addi$s0,$zero,0# i = 0
L1:addi$s1,$zero,0# j = 0
L2:addi$s2,$zero,0# k = 0
addi $t6, $zero, 0
inner:
mul$t0,$s0,$a3# load x[i][k]
add$t1,$t0,$s2# i*n+k
sll$t1,$t1,2# 8*(i*n+k)
add$t2,$a0,$t1# address of x[i][k]
lw$t3,0($t2)# load x[i][k]
mult$s2,$a3# load y[k][j]
mflo $t0
add$t1,$t0,$s1# k*n+j
sll$t1,$t1,2# 8*(k*n+j)
add$t2,$t1,$a1# address of y[k][j]
lw$t4,0($t2)# load y[k][j]
mult$t3,$t4# x[i][k] * y[k][j]
mflo $t5
add$t6,$t6,$t5# z[i][j] = z[i][j] + x[i][k] * y[k][j]
add$s2,$s2,1# k++ and test inner loop condition
bne$s2,$a3,inner#
mult$s0,$a3# store z[i][j]
mflo $t0
add$t1,$t0,$s1# i*n+j
sll$t1,$t1,2# 8*(i*n+j)
add$t2,$t1,$a2# address of z[i][j]
sw$t6,0($t2)# store z[i][j]
add$s1,$s1,1# j++ and test loop condition
bne$s1,$a3,L2
add$s0,$s0,1# i++ and test loop condition
bne$s0,$a3,L1
exit:
jr$ra