Assignment 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

PROCESSOR COMPUTING COMPUTING TIME ROUTING TIME

TIME RATIO RATIO


2 201
4 131 131/201 = 0.652 13/11 = 1.182
8 85 85/131 = 0.649 17/13 = 1.308
16 56 56/85 = 0.659 22/17 = 1.294
32 35 35/56 = 0.625 23/22 = 1.045
64 18.5 18.5/35 = 0.529 26/23 = 1.130

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

sll $t0, $s0, 2 // $t0 = f * 4

add $t0, $s6, $t0 // $t0 = &A[f]

sll $t1, $s1, 2 // $t1 = g * 4

add $t1, $s7, $t1 // $t1 = &B[g]

lw $s0, 0($t0) // f = A[f]

addi $t2, $t0, 4 // $t2 = &A[f + 1]

lw $t0, 0($t2) // $t0 = A[f + 1]

add $t0, $t0, $s0 // $t0 = A[f + 1] + A[f]

sw $t0, 0($t1) // B[g] = A[f + 1] + A[f]

Therefore the c statement is: B[g] = A[f + 1] + A[f]

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

for (int i=15; i>0; i--)


{
If (temp = = 0)
{break;}
}

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

The loop executes 4 instructions per iteration

$t1 = N

Then total number of instructions executed is 4*N

SECOND LOOP

The loop executes 4 instructions as well

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

on the value of $t2 in the first iteration

You might also like