6. Given the following C code for accessing a 3 dimensional array: int access3(int i, int...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
a The formula for the address of the element aijk in the 3dimensional array anmp can be expressed as ... View the full answer
Related Book For
Computer Organization and Design The Hardware Software Interface
ISBN: 978-0124077263
5th edition
Authors: David A. Patterson, John L. Hennessy
Posted Date:
Students also viewed these accounting questions
-
Consider the following C code fragment: if (EAX == 0) EBX = 1; else EBX = 2; Write an equivalent NASM code fragment.
-
Implement the following C code in MIPS assembly. What is the total number of MIPS instructions needed to execute the function int fib(int n){ if (n==0) return 0; else if (n 1) == return 1; else...
-
Question 6 Given the following hypothesis HO: _National student lecture attendance - _NUIG student lecture attendance =100 H1: _National student lecture attendance - _NUIG student lecture attendance...
-
On 13 May 2014, Ruben acquired 400 shares in Xantan Ltd at a cost of 1,800. On 17 July 2020, the company made a 1 for 8 bonus issue and (on the same day) Ruben sold his bonus shares for 7 each....
-
Suppose that a restaurant uses a focus group of regular customers to determine how many customers would buy a proposed new menu item at various prices. Can this information be used to estimate an...
-
Aoslia is a small country that takes the world price of corn as given. Its domestic supply and demand for corn are given by the following: a. Assume initially that Aoslia does not open to trade. What...
-
The influence of temperature on the equilibrium constant of a chemical reaction can be obtained from (a) \(\left(\frac{\partial \ln K}{\partial T} ight)=-\frac{\Delta \dot{H}}{T^{2}}\) (b) \(\ln...
-
On January 1, Patterson Corporation acquired 80 percent of the 100,000 outstanding voting shares of Soriano, Inc., in exchange for $31.25 per share cash. The remaining 20 percent of Sorianos shares...
-
Q. 1. Table 1 below provides specifications for a Cessna 172 and a Boeing 747. For each aircraft, calculate the range using the appropriate Breguet range equation. Cessna 172 Boeing 747 Empty Weight...
-
Tableau Dashboard Activity 5-1 Account for Uncollectible Accounts Using the Aging Method Review the Tableau visualization, and then answer the questions that follow. Total Accounts Receivable Amount...
-
What are the psychological ramifications associated with physician-assisted suicide?
-
Mirrors are sometimes placed in busy lobbies, waiting areas, and on elevator doors. Their purpose is often to make the time pass faster for people waiting in front of them. Which psychological...
-
Is there any situation in which the cost of waiting is strictly linear? What would such a situation look like? How does the so-called cost of waiting vary between certain situations, such as waiting...
-
If increasing the volume of production is likewise increasing the average cost per unit produced, the system is suffering from what?
-
On what do the mathematical and the psychological modelers of waiting disagree?
-
What is the body of knowledge concerning mathematical modeling of waiting lines called?
-
Calculation: In the first step of the experiment, you pipet 50 l of 4 mM CaCl into 7 ml final volume of a reaction cocktail. Then, you then add 300 l of the cocktail to each reaction tube; with the...
-
Gopher, Inc. developing its upcoming budgeted Costs of Quality (COQ) with the following information: Expense Item Budget Raw Materials Inspection $ 15,000 EPA Fine 200,000 Design Engineering 15,000...
-
Calculate the time necessary to perform a multiply using the approach given in Figure 3.7 if an integer is 8 bits wide and an adder takes 4 time units. Figure 3.7 Mplier31 Mcand Mplier30 Mcand...
-
Can we use the tail-call optimization in this function? If no, explain why not. If yes, what is the difference in the number of executed instructions in f with and without the optimization?
-
Virtualization software is being aggressively deployed to reduce the costs of managing todays high performance servers. Companies like VMWare, Microsoft and IBM have all developed a range of...
-
If a product is produced in high volume by a few large organizations, what phase of the product life cycle is it most likely in?
-
At what phase of the product life cycle are the most organizations offering the product to the customer?
-
The product life cycle suggests that what will happen to the price of a product as it ages?
Study smarter with the SolutionInn App