Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4D array MIPS assembly programming Show Matrix addition, and matrix multiplication on simple 4x4 matrices (define these in code) A= 0 5 7 2 1

4D array

MIPS assembly programming

Show Matrix addition, and matrix multiplication on simple 4x4 matrices (define these in code)

A= 0 5 7 2

1 2 5 6

6 0 1 5

1 0 6 4

B= 1 7 8 7

4 6 5 5

4 8 2 7

6 1 8 7

1 0 6 4

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

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

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

Timeline for implementation report

Answered: 1 week ago