Tom Kelliher, CS 220
Sept. 7, 2007
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;
}
Write MIPS code corresponding/solving each of the following:
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.