Question: The following RISC - V assembly code calculates the trace ( sum of the diagonal ) of a square matrix. Fill in the gaps in
The following RISCV 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
word
word
word
n: word
text #
li a # a will store the sum
la s m
lw s n #this is a pseudoinstruction equivalent to la s n; lw ss
# calculate n in s
slli s# set s to point to the next row, same column of the matrix
addi s # now set s to point to the next element in the row; this will be on the diagonal
loop: lw ts # load array element on the diagonal in t start with m
add t # add the element to the sum
add s # point to the next element in the diagonal
addi s s # decrement iterator
bne s loop #loop until you have gone through the entire array
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
