Question: 6. Given the following C code for accessing a 3 dimensional array: int access3(int i, int j, int k, { } with gcc -og

6. Given the following C code for accessing a 3 dimensional array:

6. Given the following C code for accessing a 3 dimensional array: int access3(int i, int j, int k, { } with gcc -og generating the following x86-64 assembly: access3: return a[i][j][k]; int n, int m, int p, int a[n][m][p]) movslq %r9d, %r9 leaq movslq %r8d, %r8 imulq salq addq movslq imulq %r8, %rdi $2, %rdi shrq movq imulq (,%r9,4), %rcx leaq movl ret %r9, %r8 %edi, %rdi movslq %edx, %rax movslq %esi, %rdx $2, %rcx %rcx, %rsi %rdx, %rsi 8(%rsp), %rdi (%rax , %rsi) , %rdx (%rdi, %rdx, 4), %eax a. Assuming a declaration int a[n] [m] [p], give a formula for the adress of a[i] [j][k]. b. Annotate the above assembly code to show that it computes the above formula. Specifically, annotate the arguments to the access3 function and the results of all instructions other than the ret. Your annotations should be of the form machine Element = srcExpr where machine Element should specify a x86-64 register or memory location and srcExpr should be an expression involving variables from the C program. 15-points

Step by Step Solution

3.46 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a The formula for the address of the element aijk in the 3dimensional array anmp can be expressed as ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!