Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions