ld r1, 8[X19] /* value of x[1] is stored in r1 register (as each
integer takes 8 Bytes, X[1] = *(X+8)) */
sub r0, X20, r1 /* r0 := a - x[1] */
st r0, [X19] /* store r0 value into place whose address is X19
i.e., x[0] */
add X22, r0, X21 /* c := x[0] + b */
lsl r2, c, 4 /* r2 := c >> 4 */
st r2, 8[X19] /* store r2 value into place whose address is X19+8
i.e., x[1] */
mul r4, X20, 4 /* r4 := a * 4 */
ld r5, r4[X19] /* value from the address X19+r4 = x[r4/8] = x[a/2]
is loaded into r5 */
sum r3, r5, X21 /* r3 := r5 + b */
st r3, 16[X19] /* store r3 value into place whose address is X19+16
i.e., x[2] */
sum r6, r1, r3 /* r6 := x[1] + x[2] */
mul r7, X22, 8 /* r7 := c * 8 */
st r6, r7[X19] /* r5 is stored into place whose address is X19+r7 =
x[r7/8] = x[c] */
COMMENT DOWN FOR ANY QUERIES AND,
LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.
4. Convert the below C code snippet to LEGV8 assembly code. Base address of x is...
Translate the following LEGv8 assembly into C, assuming that: X19 = f, X20 = g, X21 = h, X22 = &a SUB X9, X20, X21 CBZ X9, ELSE LSL X9, X20, #3 ADD X9, X22, X9 LDUR X19, [X9, #0] B END ELSE: LDUR X19, [X22, #0] END: SUB X21, X19, X20
convert C to LEGv8
(an example given below)
Q1 [15] Convert the following C code to LEG. Assume the following variable/register assignments: Base of A i X19 X20 int main { long long int A[6] = {1, 2, e, e, e, e}; for unsigned int i = 0; i < { A[i+2] myFunction (A[ i] , A[i+1] ); } return 0 } 4; i+ //convert to LEG //convert to LEG //convert the entire myFunction to LEG long long int myFunction...
B2. Convert the C code to MIPS assembly with only 2 efficient instructions: Register assignment: timer-v0 int timer = 0x0AC8 0001; B3. Write MIPS assembly code segment for the following C code snippet for (i - 0, i < 100; i++) -array Register assignment: i-) $ao Base of array -> $s0 array [ i+1] [i] / 2;
B2. Convert the C code to MIPS assembly with only 2 efficient instructions: Register assignment: timer-v0 int timer = 0x0AC8 0001; B3. Write...
Write an equivalent MIPS code for the following C code. Assume that the base address of an array A is stored in register 450. Variables x, i, j and h are stored in registers $t0,$t1, $t2 and $t3 respectively. do{ x = x + A[i]; i = i + j; } (while i != h); Make sure your MIPS code has sufficient comments.
3- [8 points] Write the following sequence of code into RISC-V assembler: x=x-y-z+4; Assume that x, y, and z are stored in registers x18, x19, and x20 respectively.
1. Convert the following C statement to MIPS code. Assume x, y and z are assigned to registers $s0, $s1 and $s2 respectively and the starting address of array A is $s6. x = y + z + A[3] 2. 2.Convert the following C statement to MIPS code. Assume the base address of array A is $s3 and h is assigned to register $s2 . A[7] = h + A[7]
IN MIPS AND MUST RUN IN QTSPIM
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 stored in registers Ss0, Ss1, St0 and Stl, respectively. Also assume that register Ss2 holds the base address of the array D. for (i=0; i<a; itt) for (i-0j<b:jt+)
its
brr[8]
(40%) Convert the following C-pseudo code into MIPS assembly code as a standalone program (including main and all the required directives). You can use any register. You must comply, however, with the convention of register usage. Before writing your code perform an explicit register allocation phase. Note that the C snippet is int arr[8]; int brr[4]-{1, 2, 3, 4, 5, 6, 7, 8) int i-8; while (i>-0) arrli]-brr[i-); (40%) Convert the following C-pseudo code into MIPS assembly code...
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...
C code to MIPS Translate the following C command into MIPS assembly. Assume that the base address of arrays A is stored in register $s1. 시 I-A[2] + 7;