Professional Documents
Culture Documents
Assignment 2
Assignment 2
Assignment 2
b) Find the computing time and routing time for a system with one processor.
QUESTION 2.For the MIPS assembly instructions below, what is the corresponding C
statement? 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.
Answer
QUESTION 3 i) For the loops written in MIPS assembly above, assume that the register $t1 is
initialized to the value 15. What is the value in register $s2 assuming the $s2 is initially zero?
Answer
FIRST LOOP
In the first iteration $t1 becomes 14 and $s2 becomes 2
In the 15th iteration $t1 becomes 0 and $s2 becomes 30 as the loop terminates
Therefore the value of $s2 is 30.
SECOND LOOP
If $t2 (temp) is equal to 0, the loop jumps to done label.
Let’s assume $t2 is initially 0 then the loop will never terminate because $t2 is not equal to 0.
Therefore the loop will behave as the first loop thus the final value of $s2 will also be 30.
ii) For each of the loops above, write the equivalent C code routine. Assume that the registers
$s1, $s2, $t1, and $t2 are integers A, B, i, and temp, respectively.
Answer
FIRST LOOP
for (int i=15; i>0; i--)
{
A +=2;
}
SECOND LOOP
iii) For the loops written in MIPS assembly above, assume that the register $t1 is initialized to
the value N. How many MIPS instructions are executed?
Answer
FIRST LOOP
$t1 = N
SECOND LOOP
If $t2 (which is temp) is not equal to 0 in the first iteration then total number of instructions
executed is 4*N.
If $t2 is equal to 0 the loop will jump to the done label after the first iteration and only 5
instructions will be executed. Therefore the exact number of instructions executed will depend