1. Translate function foo() in the following C code to RISC-V assembly code. Assume function bar()...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Translate function foo() in the following C code to RISC-V assembly code. Assume function bar() has already been implemented. The constraints/tips are: 1) Allocate register s1 to sum, and register s2 to i. 2) There are no load or store instructions in the loop. If we want to preserve values across function calls, place the value in a saved register before the loop. For example, we keep variable i in register s2. 3) Identify the registers that are changed in function foo() but should be preserved. Note that the callee, bar(), may change any temporary and argument registers. 4) Save registers at the beginning of the function and restore them before the exit. Your code should follow the flow of the C code. Write concise comments. Clearly mark instructions for saving registers, loop, function calls, restoring register, etc. // prototype of bar // the first argument is an address of an integer int bar(int a[], int i); int foo(int d[], int n) { } int sum = 0; for (int i = } return sum; 0; i<n; i += 1) { sum += bar (&d[i], n i); // &d[i] means d[i]'s address 1. Translate function foo() in the following C code to RISC-V assembly code. Assume function bar() has already been implemented. The constraints/tips are: 1) Allocate register s1 to sum, and register s2 to i. 2) There are no load or store instructions in the loop. If we want to preserve values across function calls, place the value in a saved register before the loop. For example, we keep variable i in register s2. 3) Identify the registers that are changed in function foo() but should be preserved. Note that the callee, bar(), may change any temporary and argument registers. 4) Save registers at the beginning of the function and restore them before the exit. Your code should follow the flow of the C code. Write concise comments. Clearly mark instructions for saving registers, loop, function calls, restoring register, etc. // prototype of bar // the first argument is an address of an integer int bar(int a[], int i); int foo(int d[], int n) { } int sum = 0; for (int i = } return sum; 0; i<n; i += 1) { sum += bar (&d[i], n i); // &d[i] means d[i]'s address
Expert Answer:
Answer rating: 100% (QA)
The C function foo provided in the image should be translated into RISCV assembly language considering the constraints and tips mentioned The provided ... View the full answer
Related Book For
Digital Design and Computer Architecture
ISBN: 978-0123944245
2nd edition
Authors: David Harris, Sarah Harris
Posted Date:
Students also viewed these programming questions
-
The above brief doesn't have an objective, budget or a timeframe. You are required to run an email marketing campaign. Add these three components into the brief and explain what the objective of the...
-
1. Summarise the approach that you're recommending for your workplace or ABRG to implement for its marketing and communications. Include the profiles created and the different marketing methods to be...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
A 4-ft-high, 3-ft-diameter cylindrical water tank whose top is open to the atmosphere is initially filled with water. Now the discharge plug near the bottom of the tank is pulled out, and a water jet...
-
Suppose you want to run some apparatus that is 95 m from an electric outlet. Each of the wires connecting you apparatus to the 120-V source has a resistance per unit length of 0.0065/m. If your...
-
Calculate the following for the year ending 30 June 2024 (using the information in the textbook) on a taxable income of $20,000, $27,000 and $35,000 for a single Australian resident taxpayer (who is...
-
What is the implication of the statement "the books are not in balance"? What corrective action should be taken?
-
Using the following information, prepare the Statement of Revenues, Expenses, and Changes in Fund Net Position for the town of Robinson Water and Sewer Enterprise Fund for the year ended June 30,...
-
The capital accounts of Hassan Khan and Dmitri Palovich have balances of $110,000 and $78,000, respectively, on January 1, 2014, the beginning of the fiscal year. On July 10, Khan invested an...
-
Marloweville, with 20,000 residents is deciding how to finance the construction of a new municipal stadium that will enhance both recreation and tourism in the area, The construction cost of the...
-
Given the cipher text: RQODMBIQAO VAAG QE HTQQG HMI PTCEIO EAAG LCIAX CI EQQE HAAO PXQGMFA IQQ RMFY YQEAK VQX VQQG CEG QETK VQQTO ACI OAAGO Perform Cryptanalysis to find out the plain text. Show all...
-
Patty Hayes owned four Personal Seat Licenses (PSLs) at the Cleveland Browns Stadium. Hayess PSLs reserved four seats on the 50-yard line, at the railing, on the north side of the stadium. As the...
-
Identify and describe the key attributes that might mitigate a red flag, suggesting that no bad act or compliance issues exist.
-
Taj Mahabub was the founder and CEO of GenAudio, a Colorado-based audio technology company. GenAudio had struggled financially practically since its formation, and Mahabub wished to secure a...
-
In September 2013, Ugo Mattera entered into a written construction contract with Baja Properties, LLC. Stephen Chad Golden, the sole owner of Baja Properties, signed the contract and addendums on...
-
Kronenberger Burgoyne, LLP, was a law firm with two equity partners who agreed to equal ownership as of 2009. Before 2009, Kronenberger had owned a majority interest in the firm, and when, in 2011,...
-
2s complement of 11001011 is ____________ a) 01010111 b) 11010100 c) 00110101 d) 11100010
-
You deposit $10,000 in a savings account that earns 7.5% simple interest per year. What is the minimum number of years you must wait to double your balance? Suppose instead that you deposit the...
-
Suppose the multicycle MIPS processor has the component delays given in Table 7.6. Alyssa P. Hacker designs a new register file that has 40% less power but twice as much delay. Should she switch to...
-
Repeat Exercise 7.26 for one of the new instructions from Exercise 7.14.
-
Is it possible to assign logic levels so that a device with the transfer characteristics shown in Figure 1.46 would serve as a buffer? If so, what are the input and output low and high levels (V IL...
-
Wakuluks approach to economic forecasting: A. is flexible and limited in complexity. B. can give a false sense of precision and provide false signals. C. imposes no consistency of analysis across...
-
Wakuluk is most likely to make significant adjustments to her estimate of the future growth trend for which of the following countries? A. Country Y only B. Country Z only C. Countries Y and Z Neshie...
-
Based on Exhibit 1, what capital market effect is Country Z most likely to experience in the short-term? A. Cyclical assets attract investors. B. Monetary policy becomes restrictive. C. The yield...
Study smarter with the SolutionInn App