Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# void mmult(double x[][], double y[][], double z[][], int n) # // Inputs: x,y,z are n X n matrices. # // Side-effect: z is modified,

image text in transcribed

image text in transcribed

image text in transcribed

# 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 jal mmult ori $v0,$0,10 # end program gracefully syscall jr $ra # return nop .data .align 2 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
Both the data cache and the instruction cache configuration can be modified in the Spim Cache simulator. Please follow the steps in the tutorial. In this lab assignment, you only need to change the configuration of the data cache. The configuration for the instruction cache should remain default. 3. Project code In this lab, you will use code similar to the solution to Project 1 as the input to the cache simulator. You can find the code (lab2-code.s) on the Project page of the course web site The code performs matrix multiplication of two 5X5 matrices. Take some time to review the code to familiarize yourself with its operation. Note the following self-help questions: How many data memory words are used? How many bytes? In what order are the data memory values accessed? Youwill use the Spim-Cachesimulator to simulatethe Both the data cache and the instruction cache configuration can be modified in the Spim Cache simulator. Please follow the steps in the tutorial. In this lab assignment, you only need to change the configuration of the data cache. The configuration for the instruction cache should remain default. 3. Project code In this lab, you will use code similar to the solution to Project 1 as the input to the cache simulator. You can find the code (lab2-code.s) on the Project page of the course web site The code performs matrix multiplication of two 5X5 matrices. Take some time to review the code to familiarize yourself with its operation. Note the following self-help questions: How many data memory words are used? How many bytes? In what order are the data memory values accessed? Youwill use the Spim-Cachesimulator to simulatethe

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions