Question

Assume we have an array int* arr = {1,21,32,43,54}. The values in arr store in the...

Assume we have an array int* arr = {1,21,32,43,54}. The values in arr store in the memory of 0(x27), 8(x27), …, 32(x27). Convert the following RISC-V code into a C program.

ld x5, 24(x27)

addi x8, x0, 0(x27)

srl x5, x5, x6

sd x5, 0(x27)

Homework Answers

Answer #1

Answer.

Step 1

RISC-V is an assembly language. It contains 32 bit integer registers and 32 bit floating point registers. It is compose through simple instructions to do a single task. In this language, data can be store in two ways, store on main memory or store on registers.
In the given problem following commands are used:

  • ld command is use to load double word.
  • addi command is used to add with sign extended.
  • srl command is used for logical right shifts.
  • sd command is used to store double word.

Step 2

RISC-V code C-code Explanation
ld x5, 24(x27) x5=arr[3] or x5=43 sets x5 equal to arr[3]
addi x8, x0, 0(x27) x8=x1+arr[0] or x8=x1+1 Add 1 to x0 and store in x8
srl x5, x5, x6 x5=x5<<x6 Logical right shifts x5 by x6 and store in x5
sd x5, 0(x27) x5=arr[0] or x5=1 store double word, initialize x5 by 1

Kindly upvote please,

Thank you.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Assume all memory locations start with unknown values. What is the contents of memory after this...
Assume all memory locations start with unknown values. What is the contents of memory after this program runs? addiu $t0, $zero, 8 addi $t1, $t0, 1 sw $t1, -4($t0) addi $t1, $t0, -4 sw $t1, 4($t0) Match the options with these mem locations. 0x0: 0x4: 0x8: 0xC: 0x10: 0x14: Options to match with mem adress 12 -4 4 5 0 9 unknown 1
Write the following program in MIPS: a) declare an array A of the following numbers: 3,...
Write the following program in MIPS: a) declare an array A of the following numbers: 3, 5, 8, 10, 12, 2, 76, 43, 90, 44 b) declare a variable called size which stores the number of element in array A, that is 10. c) write a subroutine to search for a number stored in an array and return true or false. In C++ the subroutine is as follows: search(array, size, number_To_Search) e.g. search(A, 10, 12) The subroutine should return 0...
We run the following code with an empty TLB. Calculate the TLB miss rate for data...
We run the following code with an empty TLB. Calculate the TLB miss rate for data (ignore instruction fetches). Assume i and sum are stored in registers and cool is page-aligned. #define LEAP 8 int cool[512]; ... // Some code that assigns values into the array cool ... // Now flush the TLB. Start counting TLB miss rate from here. int sum; for (int i = 0; i < 512; i += LEAP) { sum += cool[i]; } What is...
Code Example 8-1 1. int count = 1; 2. int item_total = 0; 3. int item...
Code Example 8-1 1. int count = 1; 2. int item_total = 0; 3. int item = 0; 4. while (count < 4) { 5.      cout << "Enter item cost: "; 6.      cin >> item; 7.      item_total += item; 8.      ++count; 9. } 10. int average_cost = round(item_total / count); 11. cout << "Total cost: " << item_total << "\nAverage cost: " << average_cost; (Refer to Code Example 8-1.) If the user enters 5, 10, and 15 at the prompts, the output is: Total...
In this lab, we want to get some practice with pointers -- specifically, the basic syntax...
In this lab, we want to get some practice with pointers -- specifically, the basic syntax of declaring them, storing memory addresses into them, dereferencing them, and seeing how they work with pointer arithmetic in the context of built-in, C-style arrays. Unless specified otherwise, you can use any valid variable names you wish. The requirements for this program are as follows: Part A Declare a pointer-to-int, initialized to nullptr. Declare an int variable, initialized to some value of your choice....
IN C PROGRAMMING A Tv_show structure keeps track of a tv show’s name and the channels...
IN C PROGRAMMING A Tv_show structure keeps track of a tv show’s name and the channels (integer values) that broadcast the show. For this problem you can ONLY use the following string library functions: strcpy, strlen, strcmp. You MAY not use memcpy, memset, memmove. You can assume memory allocations are successful (you do not need to check values returned by malloc nor calloc). typedef struct tv_show { char *name; int num_channels, *channels; } Tv_show; a. Implement the init_tv_show function that...
convert this code to accept int value instead of float values using python. Make sure to...
convert this code to accept int value instead of float values using python. Make sure to follow the same code. do not change the steps and make sure to point to what code you replaced. make sure to have 2 files Method:----------------------- #define a python user difined method def get_float_val (prompt): is_num = False str_val = input (prompt) #prming read for our while #while is_num == False: (ignore this but it works) old school while not is_num: try: value =...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values a variable cannot hold? How much memory will be reserved for the variable? What value a variable will hold? How the program will use the data type? Question 2 Using the structure below, which of the following statements about creating an array (size 20) of structures are not true? struct Employee{     string emp_id;     string emp_name;     string emp_sex; }; Question 2 options:...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...