Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(b): Currently, the branch delay slots are filled with flop instructions, but th

ID: 646899 • Letter: #

Question

(b): Currently, the branch delay slots are filled with flop instructions, but this is inefficient. Rearrange the instructions so that the branch delay slots are filled with useful work and that data hazard stalls are eliminated (if possible). (You may duplicate and rearrange instructions, and remove the nap instructions, but do not unroll the loop or change the instructions.) The functionality of the code must be preserved. Explain in comments why your arrangement works. Below is a small loop (inside a function) written in MIPS. We don?t care what it does, but we do care how long it takes to execute:

Explanation / Answer

Ans :- It take about 1.0 to 2.8ns(nanosecond) to execute an small loop in MIPS(Microprocessor without Interlocked Pipeline Stages)

Ans b:- When you write NOP in MIPS code it is translated to ssl $r0,$r0,0 which means shift register r0 left zero places and put the result in $r0. Since $r0 is hardwired to zero, this instruction has no effect and can be treated as a no operation. Moreover, since the numeric value for this is 0x00000000 (all zeros) it means that non-initialized memory will be treated as NOPs. However, such NOPs are accidental, they were not put there by a programmer but are being executed because an error has occurred and the processor is responding by merrily skipping through a field of NOPs.

Function:

add $t0, $zero, $a0

Loop:

lw $t1, 0($a1)          #don't need an offset, replace with lw $t1, ($a1)

lw $t2, 4($a1)

add $t3, $t0, $a2

add $t4, $t2, $t4    #swapped the bne and add instructions to eleminate nop instruction

bne$t2, $t3, Pass

Pass:

bne $zero, $t0, loop

addi $t0, $to, -1     #swapped the bne and addi instructions to eleminate nop instruction

addi $a1, $a1, 4

and $v0, $t4, $t4

jr $ra

or you can also use branch instruction to eleminate the nop instruction

We can also ignore any branching instructions when we compare instructions executed by different programs because:

A branching instruction does not update any data registers

So it has no effect on the behavior of the program

In fact, a branch instruction changes the sequence of instructions executed:

By listing the sequence of instruction executed, we have basically nullified the effect of the branch instruction

The answer is provided on the bases of my knowledge and information on the subject hope you had understood.

Thanks.