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

1. For the following C statement, write the corresponding RISC-V assembly code. Assume that the C...
1. For the following C statement, write the corresponding RISC-V assembly code. Assume that the C variables a, b, and c, have already been placed in registers x10, x11, and x12 respectively. Use a minimal number of RISC-V assembly instructions. a = b + (c − 2); 2. Write a single C statement that corresponds to the two RISC-V assembly instructions below. add e, f, g add e, h, e 3. Assume that registers x5 and x6 hold the values...
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...
In Assembly Code write an assembler code (Fibonacci.s) and show results The Fibonacci Sequence is a...
In Assembly Code write an assembler code (Fibonacci.s) and show results The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are both 1; after that, each number is the sum of the preceding two numbers. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... For example, 1+1=2, 1+2=3, 2+3=5, 3+5=8, etc. The nth Fibonacci number is the nth number in this sequence, so for example fibonacci(1)=1, fibonacci(2)=1, fibonacci(3)=2, fibonacci(4)=3, etc....
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; }
If E(X) = 5, V(X) = 3 and Y = 5 - X/3 - X, what...
If E(X) = 5, V(X) = 3 and Y = 5 - X/3 - X, what is mean of 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 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
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); }...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT