Answered step by step
Verified Expert Solution
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 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
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