first instruction i1 to i5 execute then branch then instruction i18 to i20 execute.
=> i-1,i-2,i-3,i-4,i-5,i-18,i-19,i-20 executes in pipeline mode and some stall cycles are added due to branch.
=> total time = time for executing instructions + stall time
---------------------------------------------------------------------------------------------------------------------------------
K -> number of stages in pipeline =6.
n -> number of instructions. to execute = 8 ( i-1,i-2,i-3,i-4,i-5,i-18,i-19,i-20 )
-----------------------------------------------------------------------------------------------------------------------------------
For executing i-1,i-2,i-3,i-4,i-5,i-18,i-19,i-20 instructions in pipeline time required
= (K + n-1 ) * clock cycle time
= (6 + 8-1) * 4
= 13 * 4
= 52 ns
--------------------------------------------------------------------------------------------------------------------------------------
number of stall cycles = stage at which target address available -1.
Pipeline target address is available in 4th stage
=> extra time for stall cycles = no. of stall cycle * clock cycle time
= 3*4
= 12 ns
----------------------------------------------------------------------------------------------------------------------------------------
So total time = time for executing instructions + stall time
= 52ns + 12ns
= 64ns