5. Write the MIPS minimal sequence of instructions for the following C procedure code:
int array_sum (a[], b[])
{ int i;
i =1;
for (i=1; i<100; i=i+1)
{ b[i] = D + a[i-1] + a[i] + a[i+1] ;}
}
Assume that:
C code
int array_sum (a[], b[]) {
int i;
i =1;
for (i=1; i<100; i=i+1){
b[i] = D + a[i-1] + a[i] + a[i+1] ;
}
}
$a0 = base address of array a[]
$a1 = base address of array b[]
$s1 = i
$s0 = D
MIPS code
addi $s1, $0, 1 //i = 1
addi $t0, $a0, 4 //$t0 =
&a[1]
addi $t1, $a1, 4 //$t1 =
&b[1]
Loop:
slti $t2, $s1, 100 //set $t2
when (i<100)
beq $t2, $0, Exit //if($t2 ==
0) branch to Exit
lw $t2, -4($t0) //$t2 =
a[i-1]
lw $t3, 0($t0) //$t3 =
a[i]
add $t2, $t2, $t3 //$t2 =
a[i-1] + a[i]
lw $t3, 4($t0) //$t3 =
a[i+1]
add $t2, $t2, $t3 //$t2 =
a[i-1] + a[i] + a[i+1]
add $t2, $t2, $s0 //$t2 = D +
a[i-1] + a[i] + a[i+1]
sw $t2, 0($t1) //b[i] = D +
a[i-1] + a[i] + a[i+1]
addi $t0, $t0 ,4 //$t0 =
$a[i+1]
addi $t1, $t1 ,4 //$t1 =
$b[i+1]
addi $s1, $s1, 1 //i =
i+1
j Loop
//Jump to Loop
Exit:
5. Write the MIPS minimal sequence of instructions for the following C procedure code: int array_sum...
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...
For the following C statement, write a minimal sequence of MIPS assembly instructions that does the identical operation. Assume $t1 = A, $t2 = B, and $s1 is the base address of C. A = C[0] << 4;
Translate each of the following pseudo-instructions into MIPS instructions. You should Produce a minimal sequence of MIPS instructions to accomplish the required computation. (8 Points) 1) bgt $t1, 100, Label # bgt means branch if greater than 2) ble $s2, 10, Next # ble means branch if less than or equal 3) ror $s0, $s4, 7 # ror means rotate right $s4 by 7 bits and store the result in $s0 4) neg $s5, $s4 # $s5 will have the...
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
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...
Please show the complete work.
2.22 [5]<$2.6> For the following C statement, write a minimal sequence of MIPS assembly instructions that does the identical operation. Assume $t1 -A,$t2 = B, and $s1 is the base address of C.
MIPS assembly language
Implement the following code in MIPS int array [ ] {2, 3, 4, 5, 6); int main) int num, position; scanf("%d",&num) ; position search(array, printf("The position is: num, 5); %d\n",positio int search(int array, int num, int size int position =-1; for(int i-0;i<size; i++) if(array [i]=num) { position-i; break; return position; Register map $s1: position $a0: array address $a1: num . $a2: size . $VO: return value
C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS register replacement $s0 $s1 $s2 $s3 $s4 $a0 Translate to MIPS. DO NOT USE pseudo MIPS instructions (e.g., BGE). Answer MUST use true 32-bit MIPS instructions: if(j < k ) a[j] = 1; else j = a[j];
Turn the Following c-code into MIPS assembly code. You are given the main procedure which calls multiply. You are also given the argument registers to be used. /* C-program */ int multiply (int number, int times) { int f; f = number * times return f; } # MIPS PROGRAM # assumes we have called the program leaf_example # $a0=number, $a1=times, $s0=f main: $addi $a0,$zero,3 $addi $a1,$zero,2 jal multiply # place the address into $ra j EXIT2 EXIT2: j OS...
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;