I'm trying to understand how the following MIPS code in a pipelined datapath would execute.
lw $4, 100($2)
sub $6, $4, $3
add $2, $3, $5
The MIPS instruction set has 5 stages (fetch, decode, execute, memory access, write back).
The answer is: 8 cycles but I'm having difficulty understanding why. Here is what the pipeline could look like (incomplete).
C F D E M WB
1 lw
2 sub lw
3 add sub lw
4 add sub x lw
5 add sub lw
6 add sub
7
8
Questions: Why the x (stall?) at 4 and 5? How do I come up with the cycles including 7 and 8?