Translate the following C code to LEGv8. Assume that the variables f, g, h, i, and j are assigned to registers X0, X1, X2, X3, and X4, respectively. Assume that the base address of the arrays A and B are in registers X6 and X7, respectively. Assume that the elements of the arrays A and B are 8-byte words:
B[8] = A[i] + A[j];
IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU
ANSWER:
CODE:
#offset value of A[i]
sll $t0, $x3, 2
#add the address of A[i]
add $t0, $t0, $x6
#load A[i] value to t0
lw $t0, 0($t0)
#offset value of A[j]
sll $t1, $x4, 2
#add the address of A[j]
add $t1, $t1, $x6
#load A[j] value to t1
lw $t1, 0($t1)
#add the address t1
add $t2, $t0, $t1
# B[8] = A[i] + A[j]
sw $t2, 32($x7)
I HOPE IT HELPS YOU RATE THUMBSUP PLEASE
Translate the following C code to LEGv8. Assume that the variables f, g, h, i, and...
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.9 5 $2.2, 2.3> Translate the following C code to MIPS. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively. Assume that the elements of the arrays A and B are 4-byte words: fAlBg
Assignment 3 Translate the following MIPS code to C. Assume that the variables f, g, h, i and j are assigned to registers Ss0, Ss1, Ss2, Ss3 and Ss4, respectively. Assume that the base address of the arrays A and B are in registers Ss6 and $s7, respectively. addi St0, Ss6, 4 add $t1, $s6, $0 #register $0 always holds 320s sw St1, 0(Sto) add Ss0, St1, Sto
For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables i andj are assigned to registers $50 and $s1, respectively and the base address of the arrays A and B are in registers $s6 and $57, respectively. B[i] = A[B[j]+12];
Write a program in LEGv8 assembly to copy a null-terminated ASCII string from array y to array x; converting every 'a' character in the source string to 'b' in the destination string. In other words, for each character in array y: else Assume that the base address of the arrays x and y are in registers X0 and X1, respectively. The ASCII code for characters 'a' and 'b' is 113 and 114 respectively [25 pts]. * Null-terminated means that a...
Translate the following C code to MIPS assembly. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also assume that $s2 holds the base address of the array D. for (i = 0: i < a: i++) for (j = 0: j < b: j++) D[2 * j] = i + j;
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]...
For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables i, and j are assigned to registers $s0, $s1, respectively. Assume that the base address of the arrays A and B are in registers $s2 and $s3, respectively. B[i] = A[i] - 10
7. Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a,b, i and j are in registers Ss0, Ss1, St0, and St1, respectively. Also, assume that register SS2 holds the base address of the array D. for(i-0; i<a; i++) for(j=0 ; j<b; j++)
Assume that the variables i, and j are assigned to registers $s0, $s1, respectively. Assume that the base address of the arrays A and B are in registers $s2 and $s3, respectively. B[i] = A[i] - 10