Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following source code, whereR , S , andT are constants declared wit

ID: 3638041 • Letter: C

Question

Consider the following source code, whereR , S , andT are constants declared with
#define :
int A[ R ][ S ][ T ];
int store_ele(int i, int j, int k, int *dest)
{
*dest = A[ i ][ j ][ k ];
return sizeof ( A );
}

In compiling this program, gcc generates the following assembly code:
i at %ebp+8, j at %ebp+12, k at %ebp+16, dest at %ebp+20

1 movl 12(%ebp), %edx
2 leal (%edx,%edx,4), %eax
3 leal (%edx,%eax,2), %eax
4 imull $99, 8(%ebp), %edx
5 addl %edx, %eax
6 addl 16(%ebp), %eax
7 movl A(,%eax,4), %edx
8 movl 20(%ebp), %eax
9 movl %edx, (%eax)
10 movl $1980, %eax


A. Extend Equation 3.1 from two dimensions to three to provide a formula for
the location of array element A[ i ][ j ][ k ].

B. Use your reverse engineering skills to determine the values of R , S , and T
based on the assembly code

Explanation / Answer

For part A, check out this site. Go to section: 5.6.2.1 Row Major Ordering http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html EXTREMELY thorough explanation of the memory location for multidimensional arrays, you can derive your answer from there. Still working on B.