Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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: 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
Step: 1
a The formula for the address of the element aijk in the 3dimensional array anmp can be expressed as ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started