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?
First Statement:
slt x6, x0, x5
This instruction means if x0 < x5 then x6 = 1. When x0 >= x5
then x6 = 0
Second Statement:
bne x6, x0, ELSE
This instruction means if x6 is not equal to x0 then the code jump
to method ELSE, otherwise the next statement will be executed.
Third Statement:
j DONE
This instruction means that the code jump to method DONE.
Fourth Statement:
ELSE:
addi x6, x6, 2
This instruction means that x6 = x6 + 2
Fifth Statement:
DONE:
This instruction indicates the completion of the code segment.
(a) and (b) From the first statement we can consider two scenarios where i) x6 = 0, and where ii) x6 = 1
i)
From the first statement x6 = 0 or, x0 >= x5
From the second statement in order to execute addi x0 =
1(must condition) , therefore x5 <
1
ii)
From the first statement x6 = 1 or, x0 < x5
From the second statement in order to execute addi x0 =
0(must condition) , therefore x5 <
0
Hope this helps.
Consider the following RISC-V assembly instructions: slt x6, x0, x5 bne x0, x6, ELSE j DONE ELSE: addi x6, x6, 2 DONE: a...
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...
ASSEMBLY RISCV a)Use the lui and addi instructions to store the value of 8000in x6, and then use the addi instruction to calculate the value of 8000-10 and store the result in x5 b) Use the lui and addi instructions to store the value of 23456in x6 and the value of 12345 in x7. Then use the sub instruction to calculate the value of 23456-12345 and store the result in x5 a)Use the lui and addi instructions to store the...
Registers in RISC-V are 64-bit. For the sake of simplicity, consider the following instructions operating on 32-bit registers. Assume that registers x5 and x6 hold the values 0xEEEEEEEE and 0x00000000, respectively. • (2 points) – What is the value in x6 for the following slli x6, x5, 6 • (2 points) – Using the result from the part above, what is the value in x6 for the following instruction. srli x6, x6, 6
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
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]...
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...
1 slli x30, x5, 3 add x30, x10, x30 slli x31, x6, 3 add x31, x11, x31 ld x5, 0(x30) addi x12, x30, 8 ld x30, 0(x12) add x30, x30, x5 sd x30, 0(x31) // x30 = f*8 // x30 = &A[f] // x31 = g*8 // x31 = &B[g] // f = A[f] 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...
IN RISC-V a) Consider the RISC-V code below. Indicate what is the value in register x20 after the code below is executed, and explain why; ori x18 x0 16 addi x20 x18 0 beq x20, x18, HERE add x20 x20, x20 b) Assume that the code above is part of a procedure called by main. What happens with the stack pointer during the procedure execution and why? Draw and explain. c) Add instructions to the above code to implement your...
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...
2. The table below holds MIPS assembly code fragments with different branch instructions LOOP addi $s2. $s2. 2 subi $t1. st1. 1 bne t1. 0. LOOP DONE: LOOP: it st2. $0. stl beq t2. 0. DONE addi $s2. Ss2. 2 LOOP DONE: For the loops written in MIPS assembly in the above table, assume that the register Şt1 is initialized to the value of 10. What is the value in register $s2 assuming that $s2 initially has a value of...