Question
SKELETON: .data # the next two lines define an array (mdArray as a 2x2 multidimensional array) mdArray: .word 2,5 .word 3,7 size: .word 2 #dimension
SKELETON:
.data # the next two lines define an array (mdArray as a 2x2 multidimensional array) mdArray: .word 2,5 .word 3,7
size: .word 2 #dimension of the array (2x2 in this case, note this is only for square matrices) .eqv DATA_SIZE 4 # number of bytes per element, 4 for ints, 1 for chars, 8 for doubles
.text main: la $a0, mdArray # base address lw $a1, size # size jal sumDiagonal #sum of diagonals, in our starting example, this is 9. move $a0, $v0 # this is because sumDiagonal will return it's last value in $v0 li $v0, 1 syscall
#and done li $v0, 10 syscall
sumDiagonal:
li $v0,0 #sum =0 li $t0,0 #t0 as the index
sumLoop: #The next 4 lines are the bit you need to derive and fill in yourself mul $t1,$a1,$t0 add $t1,$t1,$t0 mul $t1, $t1, DATA_SIZE add $t1 ,$t1,$a0 lw $t2, ($t1) #getting element add $v0, $v0, $t2 # sum = sum + mdArray[i][i]
addi $t0, $t0, 1 # i = i+1 blt $t0, $a1, sumLoop #if i < size, loop again jr $ra #ends sum diagonal
|
Modify your program to work on a 4x4 array and show that it works.#row-major order
Show Matrix addition, and matrix multiplication on simple 4x4 matrices (define these in code), e.g.
Hand in for the 2D part:
Code with the corrected 4 lines for summing the diagonals(I've done that in the skeleton)
Code for matrix multiplication and addition testing the two sample matrices[i can't figure out this part]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started