Question

In: Computer Science

3 – Write the following sequence of code into the RISC-V assembler. Assume that x, y,...

3 – Write the following sequence of code into the RISC-V assembler. Assume that x, y, and z are stored in registers x18, x19, and x20 respectively.

z = x - 2;

x = z +4 - y;

Solutions

Expert Solution

Given assumption is that x, y, and z are stored in registers x18, x19, and x20 respectively.

z = x - 2;

x = z +4 - y;

The code in RISC-V has been given below:

addi x20, x18, -2 // z=x-2
addi x20, x20, 4 // z=z+4
sub x18, x20, x19 // x= z-y;
HLT

Output:

An output with online RISC-V interpreter with x18=15 and x19=6 has been shown below. The final register contents are: x18=11, x19=6, x20=17.


Related Solutions

What does the RISC-V code below do? Write the C equivalent. Assume that i is in...
What does the RISC-V code below do? Write the C equivalent. Assume that i is in register x5 and that the base address of array A that holds doubleword integers is in x20. addi x5, x0, 0 addi x6, x0, 50 addi x28, x20, 0 loop: bge x5, x6, end ld x7, 0(x28) bge x7, x0, next sub x7, x0, x7 sd x7, 0(x28) next: addi x5, x5, 1 addi x28, x28, 8 jal x0, loop end: Can you rewrite...
assume that the data are stored in variable names x and y. write a matlab code...
assume that the data are stored in variable names x and y. write a matlab code to plot the quadratic spline and along with the data points x= 1 2 3 4 5 6 y= 40 78 125 256 348 425
Write the following Python code: A string X is an anagram of string Y if X...
Write the following Python code: A string X is an anagram of string Y if X can be obtained by arranging all characters of Y in some order, without removing any characters and without adding new characters. For example, each of the strings "baba", "abab", "aabb" and "abba" is an anagram of "aabb", and strings "aaab", "aab" and "aabc" are not anagrams of "aabb". A set of strings is anagram-free if it contains no pair of strings which are anagrams...
Convert the following C program into the RISC-V assembly code. You should look up a table...
Convert the following C program into the RISC-V assembly code. You should look up a table to convert the lines manually and you can use "ecall" when appropriate (Don't make it too complicated than it needs to be): #include int main() { int x = 30, y = 17; printf("x * y = "); printf("%d\n", x*y); return 0; }
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main()...
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main() { int i = 2, j = 2 + i, k; k = i * j; printf("%d\n", k + j); return 0; } 2) #include <stdio.h> int main() { int i = 2, j = 2 + i, k = j / 2; if (k == 1) { printf("%d\n", j) k = k * 2; if ( k == j) { printf("%d\n|, j); }...
Run the following RISC-V codes separately and explain what each code does and how you interpret...
Run the following RISC-V codes separately and explain what each code does and how you interpret the register results: Code 1. addi x3, x3, 1 slli x3, x3, 62 addi x4, x4, 7 mul x5, x4, x3 mulh x6, x4, x3 Code 2. addi x3, x3, 1 slli x3, x3, 63 addi x4, x4, 1 mul x5, x4, x3 mulhsu x6, x4, x3 Code 3. addi x3, x3, 1 slli x3, x3, 63 addi x4, x4, 1 mul x5, x4,...
Let f(x,y)= (3/2)(x^2+y^2 ) in 0≤x≤1, 0≤y≤1. (a) Find V(X) (b) Find V(Y)
Let f(x,y)= (3/2)(x^2+y^2 ) in 0≤x≤1, 0≤y≤1. (a) Find V(X) (b) Find V(Y)
Let X ∈ L(U, V ) and Y ∈ L(V, W). You may assume that V...
Let X ∈ L(U, V ) and Y ∈ L(V, W). You may assume that V is finite-dimensional. 1)Prove that dim(range Y) ≤ min(dim V, dim W). Explain the corresponding result for matrices in terms of rank 2) If dim(range Y) = dim V, what can you conclude of Y? Give some explanation 3) If dim(range Y) = dim W, what can you conclude of Y? Give some explanation
Write a program in "RISC-V" assembly to convert an ASCII string containing a positive or negative...
Write a program in "RISC-V" assembly to convert an ASCII string containing a positive or negative integer decimal string to an integer. ‘+’ and ‘-’ will appear optionally. And once they appear, they will only appear once in the first byte. If a non-digit character appears in the string, your program should stop and return -1.
A single product (A) moves in sequence through 3 operations: V, W, and X. The processing...
A single product (A) moves in sequence through 3 operations: V, W, and X. The processing time at each operation (in minutes per unit) is 10, 20 and 10 respectively. If the process batch size and the transfer batch size are both 100, what is the total amount of time required to process the batch? If the transfer batch size is reduced to 50, now how much total time will be required to complete the batch (do not worry about...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT