Your cart is currently empty!
Please submit individual source files for coding exercises (see naming conventions below) and a single solution document for non-coding exercises (.txt or .pdf only), when appropriate. Your code and answers need to be documented to the point that the graders can understand your thought process. Full credit will not be awarded if sufficient work is…
Please submit individual source files for coding exercises (see naming conventions below) and a single solution document for non-coding exercises (.txt or .pdf only), when appropriate. Your code and answers need to be documented to the point that the graders can understand your thought process. Full credit will not be awarded if sufficient work is not shown.
struct IntArray { int length; int *dataPtr;
};
Hint: you’ll need two malloc calls – one for the instance and one for the instance’s dataPtr (a pointer to an int array of size length).
Name your source file 3-1.c.
Here is output from a sample run of the application (your output does not need to match exactly):
Enter length: 5
Enter int: 3
Enter int: 5
Enter int: 7
Enter int: 8
Enter int: 2
[ 2, 3, 5, 7, 8 ]
When compiled, the resulting IA32 code is:
movl 12(%ebp), %edx
subl 16(%ebp), %edx
movl %edx, %eax
sall $31, %eax
sarl $31, %eax
imull 8(%ebp), %edx
xorl %edx, %eax
Parameters x, y, and z are stored at memory locations with offsets 8, 12, and 16, respectively, relative to the address in register %ebp. The return value will be stored in register %eax.
Your task is to reverse engineer the C code, specifically to write a C implementation for the decode function that is functionally equivalent to the compiled IA32 code above.
Here are some test runs:
decode(1, 2, 4): -2
decode(4, -8, -12): -16
Also write a main() function to test your function. Name your source file 3-2.c
Zip the source files and solution document (if applicable), name the .zip file <Your Full Name>Assignment3.zip (e.g., EricWillsAssignment3.zip), and upload the .zip file to Canvas (see Assignments section for submission link).