Question: Write an x86-64 procedure/function called sum that does the following: It is passed two parameters, array and size, by the procedure/function that calls it. The
Write an x86-64 procedure/function called sum that does the following:
It is passed two parameters, array and size, by the procedure/function that calls it. The first parameter is a pointer to the beginning of an array of shorts (2-byte values), and the second parameter is the number of elements in the array. sum returns an short value. A C-language prototype for the function would be:
short sum(short *array, short size);
consider the C-language declarations to determine whether the values in the array are signed or unsigned.
sum() computes the sum of the elements in the array, calls printf to print the value (Assume that an appropriate format string has been placed in read-only memory with a label .LCO), and also returns the sum result to sum()s caller in register %ax. Make sure that your sum() function does both!
Be sure to do the proper stack set up work at the beginning and end of the procedure/function, and be sure to save and restore the values of any callee save registers that you modify. Since sum() calls printf(), note that caller saved registers will also have to be considered. Also, be sure to leave the stack in the appropriate state for the return instruction. You can assume that there is no overflow on any operation.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
