a)
There are 4 instructions in this code
1) ori x18 x0 16
This will or the x0 with 16 value and the result will be stored in x18.
the operation will be
x18 = x0 | 16
2) addi x20 x18 0
this will sum up the new x18 value we get after or and the result will be stored in x20.
basically
x20 = x18 + 0
3)
beq is a branch if equal instruction this will check the value of x20 and x18.
if the value are equal then it will go to HERE statement.
so a comparison wioll happen here.
4)
add x20 x20 x20
this will double the value stored in x20 register. so x20 = x20+x20.
b)
The stack pointer will be incremented with each instrcuction call. In this case the stack pointer value will be updated by one as soon as the branch instruction is incountered.
c)
The stack pointer value is generally stored in a register in a CPU. After every instruction you can read the value of the stack pointer and check the value.
This can be done by a simple mov instruction.
mov x5 , x28 assuming x28 is the stack register.
IN RISC-V a) Consider the RISC-V code below. Indicate what is the value in register x20...
Problem 4 (30 points) a) Consider the RISC-V code below. Indicate what is the value in register x20 after the code below is executed, and explain why; х18 х0 16 ori addi x20 х18 0 beg x20, х18, НERE x20 х20, х20 add HERE Problem 4 (30 points) a) Consider the RISC-V code below. Indicate what is the value in register x20 after the code below is executed, and explain why; х18 х0 16 ori addi x20 х18 0 beg...
Consider the following RISC-V loop: (i) LOOP: beq x6, XO, DONE (ii) addi x6, x6, -1 addi x5, x5, 2 (iv) slli x7, x5, 1 (iv) bge x5, XO, DONE (vi) jal x0, LOOP (vii) DONE: some-other-instruction Assume that the register x6 is initialized to the value 5, and x5 and x7 to the value 0. Find... a) Final value of x5 at the end of execution b)Final value of x7 at the end of execution c)Total number of instructions...
Please do the following problems 1. translate into RISC-V Assembly variable rpt in x19 register. if(rpt>0){ rpt=rpt-1; goto loop } 2. Translate the following Risc-V code into C. variable 'i' in register x5, variable 'result' in x6 ,base address of integer 'memarray' in x10 addi x6,x0,0 addi x29,x0,100 LOOP: ld x7,0(x10) add x5,x5,x7 addi x10,x10,8 addi x6,x6,1 blt x6,x29, LOOP
Consider the following RISC-V assembly instructions: slt x6, x0, x5 bne x0, x6, ELSE j DONE ELSE: addi x6, x6, 2 DONE: a)For what value(s) of x5 is the addi instruction executed? b)Why?
Problem 1 (15 points) Translate the C code below into RISC-V, knowing that the values of i and j are in registers x28 and x29, respectively. The base address of array B is in register x30, and the base address of array C is in register x31.
Translate the following C code into RISC-V Assembly. (no need to implement the prints just use ecall) int a[] = {2,2,5,3,4,8,3}; int b[] = {1,4,2,0,-1,5,4}; int z[7]; void multiply(int* a, int* b, int* c, int d) { for (int i=0; i < d; i++) { c[i] = a[i] * b[i]; } } int main() { int n = 7; multiply(a,b,z,n); printf("%s", "res: "); for (int i = 0; i < z; i++) { printf("%d", d[i]); } printf("\n"); return 0; }
2.4 For the RISC-V assembly instructions below, what is the corresponding C statement? Assume that the variables f, g, h, i, and j are assigned to registers x5, x6, x7, x28, and x29, respectively. Assume that the base address of the arrays A and B are in registers x10 and x11, respectively. silix30, x5, 3 // x30=f*8 add x30, x10, x30 // x30=&A [f] s111 x31, x6 , 3 // x31 = g.8 add x31, x11, x31 // x31=&B [g]...
(C++ concept on local variable) On page 14 of the “Pointers and Memory” handout there is a reference to the “Amperand (&)” Bug in the TAB() function. Draw a trace of the local variables of the functions Victim() and TAB() on the run-time stack as these functions are executed. Your diagram should be similar to the one provided on page 13. Your diagram should depict exactly three instances in program execution - T1: Right after the first statement of Victim(),...
Problem 2.4: For the RISC-V assembly instructions below, what is the corresponding C statement? Assume that the variables f, g, h, i, and j are assigned to registers x5, x6, x7, x28, and x29, respectively. Assume that the base address of the arrays A and B are in registers x10 and x11, respectively. х30, х5, 3 add x30, x10, х30 // x30 %3D &A[F] slli x31, х6, 3 add x31, x11, х31 // х31 %3D &B[g] x5, 0(х30) // x30...
2.7 5<S$2.2, 2.3> Translate the following C code to RISC-V. Assume that the variables f, g, h, i, and j are assigned to registers x5, x6. x7. x28, and x29, y. Assume that the base address of the arrays A and B are in registers x10 and x11, respectively. Assume that the elements of the arrays A and B are 8-byte words: 2.7 5 Translate the following C code to RISC-V. Assume that the variables f, g, h, i, and...