Question
I need a little help with #4. I have no idea what the hell the assembly code corresponding to the functions means. I've included the
I need a little help with #4. I have no idea what the hell the assembly code corresponding to the functions means. I've included the first two as a reference.
1. Implement function sum() that takes as input an array of integers a and an integer n, sums up the first n integers of array a using a for loop, and returns the sum. 2. Redo the previous problem by implementing function sum2() that uses pointer arithmethic (for example, *(a+i)) instead of array indexing (for example, a[i]).
4. After completing the first two problems, open the file hw3.s, find the assembly code corresponding to functions sum and sum2 from problem 1, and then find in each the assembly instructions corresponding to the body of the for loop you used in your implementations of functions sum and sum2. Write the assembly instructions you found AS A COMMENT in file hw3.c.
For the first two (which may be comically wrong) I have:
// Problem 1 long sum(int arr[], int n) { // initialize sum int sum = 0; //iterate through elements for (int i = 0; i < n; i++) sum += arr[i]; return sum; }
// Problem 2 long sum2(long a[], long n, int *ptr) { for(i=0; i < n; i++) sum = sum + *ptr; ptr++; return sum;
I just don't know what exactly #4 is asking for or what it's supposed to look like.
hw3.c:
#include
// Problem 1 long sum(int arr[], int n) { // initialize sum int sum = 0; //iterate through elements for (int i = 0; i < n; i++) sum += arr[i]; return sum; }
// Problem 2 long sum2(long a[], long n, int *ptr) { for(i=0; i < n; i++) sum = sum + *ptr; ptr++; return sum; }
// Problem 3 long decode2 (long x, long y, long z) { int main() long x,y,z,n; printf(" Enter the value of x:"); scanf("%ld",&x); printf(" Enter the value of y:"); scanf("%ld",&y); printf(" Enter the value of z:"); scanf("%ld",&z); n=decode2(x,y,z); printf(" Result of decode2(%ld,%ld,%ld) is %ld ",x,y,z,n); return 0; } long decode2(long x,long y,long z) { long r; y=y-z; x=x*y; r=y; r=r<<63; r=r>>63; r=r^x; return r; }
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