Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following RISC - V assembly code calculates the trace ( sum of the diagonal ) of a square matrix. Fill in the gaps in

The following RISC-V assembly code calculates the trace (sum of the diagonal) of a square matrix. Fill in the gaps in the code. For registers. use the ABI name from the card given below (second column). For immediate operands, use decimal numbers, without leading zeros.
# sum of the diagonal of a square matrix
# matrix allocation in memory
.data
m: .word 1,2,3,4
.word 5,6,7,8
.word -1,20,3,-4
.word 9,2,8,5
n: .word 4
.text #
li a0,0 # a0 will store the sum
la s0, m
lw s1, n #this is a pseudoinstruction equivalent to la s1, n; lw s1,0(s1)
# calculate 4*n in s2
slli s2,__,__# set s2 to point to the next row, same column of the matrix
addi s2,__,__ # now set s2 to point to the next element in the row; this will be on the diagonal
loop: lw t0,__(s0) # load array element on the diagonal in t0, start with m(0,0)
add __,__, t0 # add the element to the sum
add __, s0,__ # point to the next element in the diagonal
addi s1, s1,-1 # decrement iterator
bne s1,__, loop #loop until you have gone through the entire array

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_2

Step: 3

blur-text-image_3

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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

Do you usually feel alert when you wake up in the morning? Yes No

Answered: 1 week ago