a. [70 points] Implement the C code snippet in RISC-V assembly language. Use s0-s2 to hold...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
a. [70 points] Implement the C code snippet in RISC-V assembly language. Use s0-s2 to hold the variable i, j, and min_idx in the function selectionSort. Be sure to handle the stack pointer appropriately. The array is stored on the stack of the selection Sortfunction. Clearly comment your comments b. [30 points] Assume that the selectionSort is the function called. Draw the status of the stack before calling selectionSort and during each function call. Indicate stack addresses and names of registers and variables stored on the stack; mark the location of sp; and clearly mark each stack frame. Assume the sp starts at 0x8000. 1. Consider the following C code snippet. void swap(int *xp, int "yp) int temp = *xp; *xp = "yp: "yp = temp; } void findMinimum(int arr], int N) ( Il variable to store the index of minimum element int min_idx = 0; int min_E= arr[min_idx]; II Traverse the given array for (int i=1;i< N;i++) { IlIf current element is smaller than min_idx then update it if (arr[i] < min_E) { min_idx = i; } return min_idx; min E = arr[min_idx]; } /* Function to sort an array using selection sort"/ void selectionSort(int arr], int n) { int i, j, min_idx; II One by one move boundary of unsorted subarray for (i =0; i <n-1; i++) ( II Find the minimum element in unsorted array min_idx=findMinimum(&arr[i], n-i); II Swap the found minimum element with the first element if(min_idx != i) swap(&arr[min_idx], &arr[i]); } int i, j, min_idx; Il One by one move boundary of unsorted subarray for (i=0; i <n-1; i++) ( Il Find the minimum element in unsorted array min_idx = findMinimum(Carr[i], n-i); // Swap the found minimum element with the first element if(min_idx != i) swap(&arr[min_idx], &arr[i]); a. [70 points] Implement the C code snippet in RISC-V assembly language. Use s0-s2 to hold the variable i, j, and min_idx in the function selectionSort. Be sure to handle the stack pointer appropriately. The array is stored on the stack of the selection Sortfunction. Clearly comment your comments b. [30 points] Assume that the selectionSort is the function called. Draw the status of the stack before calling selectionSort and during each function call. Indicate stack addresses and names of registers and variables stored on the stack; mark the location of sp; and clearly mark each stack frame. Assume the sp starts at 0x8000. 1. Consider the following C code snippet. void swap(int *xp, int "yp) int temp = *xp; *xp = "yp: "yp = temp; } void findMinimum(int arr], int N) ( Il variable to store the index of minimum element int min_idx = 0; int min_E= arr[min_idx]; II Traverse the given array for (int i=1;i< N;i++) { IlIf current element is smaller than min_idx then update it if (arr[i] < min_E) { min_idx = i; } return min_idx; min E = arr[min_idx]; } /* Function to sort an array using selection sort"/ void selectionSort(int arr], int n) { int i, j, min_idx; II One by one move boundary of unsorted subarray for (i =0; i <n-1; i++) ( II Find the minimum element in unsorted array min_idx=findMinimum(&arr[i], n-i); II Swap the found minimum element with the first element if(min_idx != i) swap(&arr[min_idx], &arr[i]); } int i, j, min_idx; Il One by one move boundary of unsorted subarray for (i=0; i <n-1; i++) ( Il Find the minimum element in unsorted array min_idx = findMinimum(Carr[i], n-i); // Swap the found minimum element with the first element if(min_idx != i) swap(&arr[min_idx], &arr[i]);
Expert Answer:
Answer rating: 100% (QA)
This question involves translating a C code snippet into RISCV assembly language and illustrating the stacks status before and during function calls Heres an introduction to provide context In this ex... 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
-
b) A tug-of-war team pulls on a cart as illustrated in Fig. 3. There is no fric- tion between the cart and surface. A black rope connects Denise and the cart while a gray rope connects Cindy and...
-
Consider the following C code snippet.? (a) Implement the C code snippet in MIPS assembly language. Use $s0 to hold the variable i. Be sure to handle the stack pointer appropriately. The array is...
-
How many MIPS instructions does it take to implement the C code from Exercise 2.27? If the variables a and b are initialized to 10 and 1 and all elements of D are initially 0, what is the total...
-
Many areas have attempted to increase the amount of recycled waste lubricating oil by requiring service stations to serve as collection centers or by instituting deposit-refund systems. On what...
-
What is wrong with the following calculation? (Guido Ubaldus thought that this proved the existence of God because something has been created out of nothing.) 0 = 0 +0 + 0 +.. - (1 - 1) + (1 1) + (1...
-
Regarding Vitality Group - internationalization of health tech. Explain the International strategic alliances of VG?
-
The following table gives the vapor pressure of water for various temperatures, previously reported in Exercise 5.2. Exercise 5.2 The following table gives the vapor pressure of water for various...
-
1. What is the macro and industry environment in the Southeast Asian region for the entrance of new budget airlines? What opportunities and challenges are associated with this environment? 2. How...
-
Business Law Assignment: 2.) Accidents on the workplace: methods of treatment. b.) In your research paper, explore how different businesses handle such situations. Are these methods always legal?
-
Financial statement data of ABC Fencing, Inc. include the following items: Cash .................... $ 21,000 Short-Term Investments .......... 25,000 Accounts Receivable, Net .......... 102,000...
-
Explain the difference between the mean, the median, and the mode.
-
A classmate or coworker suggests that it is redundant to include both an executive summary and an introduction in a report. How would you explain the different functions of an executive summary and...
-
Many of the routine messages in this chapter are just a few sentences long. Explain why using each phase of the ACE communication processanalyzing, composing, and evaluatingis helpful even for short,...
-
What are the main goals of a presentation opening?
-
How does being concise differ from simply reducing the length of your communication?
-
What are three types of paraphrasing?
-
You were appointed, on 1 October 2021, as a mortgage adviser by a building society. A customer in his thirties is purchasing a house and has asked you for advice on the mortgages. The purchase price...
-
Write a program to move a signed number from smaller register to bigger register. Hint: movzx ax, bl Topic: Data Related Operators and Directives in assembly language
-
Repeat Exercise 7.1, assuming that the signal has a stuck-at-1 fault. Data from problem 1 Suppose that one of the following control signals in the single-cycle MIPS processor has a stuck-at-0 fault,...
-
What does the following SystemVerilog statement do? result = | (data[15:0] & 16'hC820);
-
Find a minimal Boolean equation for the function in Figure 2.85. Remember to take advantage of the dont care entries. Figure 2.85 Truth table for Exercise 2.28 Oo HO H OHOH OHOHOHOH
-
Why should projects be linked to the organisation's Strategic Plan?
-
What is the BCG matrix and how is it used?
-
Explain the role projects play in the delivery of an organisation's strategy
Study smarter with the SolutionInn App