Question: hello i need help on this homework. here is my main.cp #include #include int prog2(int i, int j, int *k, int a[5], int *l); int

hello i need help on this homework.

hello i need help on this homework. here is my main.cp #include

#include int prog2(int i, int j, int *k, int a[5], int *l);

here is my main.cp

#include #include

int prog2(int i, int j, int *k, int a[5], int *l);

int main() { int k = 6; int l = 0, res; int a[5] = {7, 0, 8, 0, 3};

res = prog2(6,9,&k,a,&l); if(res != 9-6) { printf("return value should be=%d; got=%d ", 9-6, res); assert(0); } if(k != 30) { printf("k*5: expected=30, got=%d ", k); assert(0); } if(l != 18) { printf("array sum: expected=18, got=%d ", l); assert(0); }

printf("j-i= %d ", res); printf("k*5= %d ", k); printf("array sum= %d ", l);

a[1] = l; res = prog2(11,17,&k,a,&l); if(res != 17-11) { printf("return value should be=%d; got=%d ", 17-11, res); assert(0); } if(k != 30*5) { printf("k*5*5: expected=150, got=%d ", k); assert(0); }

if(l != 18*2) {

printf("array sum 2: expecred=36, got=%d ", 1);

assert(0);

}

printf("j-1= %d ", res);

printf("k*5*5= %d ", k);

printf("array sum 2= %d ", 1);

return 0;

}

i need help with this prog2.s please include comment! thanks!

.globl prog2

prog2:

push1 %ebp

#implement here

~

~

In this assignment, you will write an assem bly program in the provided file prog2.s. The file will implement a function with the prototype: int prog2 (int i, int j, int *k, int a[5], int 1); This function will do three things 1. Return j - i 2. Set *k5 (*k) It is NOT allowed to use any multiplication or division instructions. 3. Set+1 a[0] You are not required to use conditional jumping for this task, but you may get extra credits for using conditional jumpin,g Note that, when you modify any callee-save register (%ebx, %edi), you need to save and restore its old value. + a[1] + a[2] + a[3] + a[4]; = %esi, . or Note: You are required to write a comment for each instruction to explain its purpose. You can write a comment by beginning with the # sign in your assembly code. I suggest you get this working in three distinct steps: 1. First, write a function taking the above arguments, but the only thing it does is return j - i. You can test this function by nunning the provided xtest program. (Hint: the return value should be stored in %eax.) Second, try to use the address passed in as the k parameter to change the caller's variable. You need to get the integer stored at the address, multiply it by 5 (without using any multiplication or division instruction), and then store the computed value at the address. Third, try to use the address passed in as the a parameter to read integers stored in the array. Note that the address is the starting address of the array, and you need to calculate an appropriate offset to read each array element 2. 3. In this assignment, you will write an assem bly program in the provided file prog2.s. The file will implement a function with the prototype: int prog2 (int i, int j, int *k, int a[5], int 1); This function will do three things 1. Return j - i 2. Set *k5 (*k) It is NOT allowed to use any multiplication or division instructions. 3. Set+1 a[0] You are not required to use conditional jumping for this task, but you may get extra credits for using conditional jumpin,g Note that, when you modify any callee-save register (%ebx, %edi), you need to save and restore its old value. + a[1] + a[2] + a[3] + a[4]; = %esi, . or Note: You are required to write a comment for each instruction to explain its purpose. You can write a comment by beginning with the # sign in your assembly code. I suggest you get this working in three distinct steps: 1. First, write a function taking the above arguments, but the only thing it does is return j - i. You can test this function by nunning the provided xtest program. (Hint: the return value should be stored in %eax.) Second, try to use the address passed in as the k parameter to change the caller's variable. You need to get the integer stored at the address, multiply it by 5 (without using any multiplication or division instruction), and then store the computed value at the address. Third, try to use the address passed in as the a parameter to read integers stored in the array. Note that the address is the starting address of the array, and you need to calculate an appropriate offset to read each array element 2. 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!