This C segment while (A[i] != k) i = i + j uses both a conditional branch and an
ID: 3884994 • Letter: T
Question
This C segment while (A[i] != k) i = i + j uses both a conditional branch and an unconditional jump each time through the loop (see below). Variables i, j, and k correspond to registers $s3, $s4, and $s5, and the base (start address) of the integer array A in $s6. The result of the program is the final value of the index i in $s3. Code before optimization Loop: add $t1, $s3, $s3 # Temporary register $t1 = i * 2 add $t1, $t1, $t1 # Temporary register $t1 = i * 4 add $t1, $t1, $s6 # Temporary register $t1 = address of A[i] lw $t0, 0($t1) # Temporary register $t0 = A[i] beq St0, $s5, Exit # goto Exit if A[i] = k add $s3, $s3, $s4 # i = i + j j Loop # goto Loop a. Rewrite the assembly code so that it executes at most one branch or jump each time through the loop (i.e., no more than one jump/branch executed per iteration).. b. If the number of times when (A[i] != k) is true is 10, what is the number of instructions executed before and after optimization.Explanation / Answer
#include <stdio.h>
int main(void)
{
return 0;
}
2. Let us add one global variable in program, now check the size of bss (highlighted in red color).
#include <stdio.h>
int global; /* Uninitialized variable stored in bss*/
int main(void)
{
return 0;
}
#include <stdio.h>
int main(void)
{
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.