Translate the following C code to MIPS assembly code. Assume that the value of i is in register $t0, and $s0 holds the base address of the integer MemArray
if (i > 10)
MemArray[i] = 0;
else
MemArray[i] = -MemArray[i];
I considered it as word directive; if any other accordingly offset will change
MIPS PROGRAM :-
li $t1, 10
sll $t2, $t0, 2
#offset for i
add $t3, $s0, $t2 #address of
MemArray[i]
bgt $t0,$t1,IF_CON #condition
ELSE:
#else body
lw $t4,0($t3)
sub $t4, $0, $t4 #changing sign
sw $t4,0($t3)
j NEXT
IF_CON:
#if body
li $t4,0
sw $t4,0($t3) #storing
zero
NEXT:
Translate the following C code to MIPS assembly code. Assume that the value of i is...
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;
Using beq only, not bge! 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 $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds the base address of the integer array D. Comments are required. for(i=1; i<a; i++) for(j=1; j<b; j++) D[2*j] = i + j;
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+)
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++)
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;
Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Register allocations - i $s0 - j $s1 - base of A[] $s2 - base of B[] $s3 2) A[3] = B[i] + B[j]; 3) i = 0; while (j != A[i]) { i++; }
B2. Translate the following MIPS assembly instruction into machine language: lw $t8, 100($s0) B3 Write MIPS assembly code segment for the following C code snippet: for (i - O i < 10i i++) i array[i+l] - array [i8; Register assignment: i-> Şa0 Base of array -> $s0 B2. Translate the following MIPS assembly instruction into machine language: lw $t8, 100($s0) B3 Write MIPS assembly code segment for the following C code snippet: for (i - O i Şa0 Base of...
Using MIPS: Consider the following fragment of C code: for i=0: i < = 100: i = i + 1) {a[i] = b[i] + c;} Assume that a and bare arrays of words and the base address of a is in $a0 and the base address of b is in $a1. Register $t0 is associated with variable i and register $s0 with c. Write the code for MIPS. How many instructions are executed during the running of this code? How...
Translate the following C++/Java Code snippets into MIPS. Assume readInt is some value already read from the keybaord. if (readInt > 0 && readInt < 500) {y = readInt *10;} else {y = readInt *100;} # readInt $s0 # y $s1 1i $t0 500 # 500 for if condition 1i $t1 10 # 10 for multiplication 1i $t2 100 # 100 for multiplication
For the following C statement, what is the corresponding MIPS assembly code? Assume the arrays hold 16-bit integer values, $ s0 is the base for array X, $ s1 is the base for array Y, and $ t0 and $ t1 are index variables i and j respectively. Comment code X [j] = Y [i + j];