Tom Kelliher, CS 240
Sept. 9, 2005
None.
Logical and branch instructions.
Intro to Linux.
Write MIPS code fragments corresponding to the following:
if (i < 12) ++i; else --j;
i = 1;
j = 0;
while (i < 200)
{
j += i;
i *= i;
}
The class, working as a team, is to e-mail the solution to the following problems to me (I'll collect the solutions and e-mail them as one to the class.) Let me know who participated in the solution of what problem(s).
j = 0; for (i = 0; i < 10; ++i) j += i;
j = 0;
for (i = 0; i < 10; ++i)
if (i > 5)
j += i;
while (i > 0 && i < 10) ++i;
if (i < 12 && j > 3 || k != 0) ++i; else if (i == 33) --j; else k += 2;
while (save[i] == k) i += k;requires execution of both a conditional branch and an unconditional jump each time through the loop. Produce the naive code.
Optimize the naive code so that only a conditional branch is executed each time through the loop.
$a0.
$a1.
$v0.