Question: Consider a function sum below designed to calculate the sum of the neighbors of an element at position ( i , j ) in a
Consider a function sum below designed to calculate the sum of the neighbors of an element at position i j in a D array represented in a linear array format. Here's a quick breakdown:
val is a pointer to the array.
i j are the coordinates of the current element.
n is the number of columns in the D array.
The function calculates the sum of the elements directly above, below, to the left, and to the right of i j
long sum long val long i long j long n Sum neighbors of ij
long up down, left, right, sum;
up valin j ;
down valin j ;
left valin j;
right valin j;
sum up down left right;
return sum;
The function is rewritten as an optimized function long sumopt
long sumoptlong val long i long j long n
long up down, left, right, sum, opt in j;
up valopt n;
down valopt n;
left valopt ;
right valopt ;
sum up down left right;
return sum;
Write assembly in RISC V codes for the function with and without optimization. Comment on the results.
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
