mov $10, %eax
add $2, %eax
mov $4, %ebx
mov $5, %ecx
add $1, %ebx
add $1, %ecx
add %ecx, %eax
add %ebx, %eax
If you have the above assembly, the general 5-stage pipeline would look something like the below but since there is a data dependence, the first instruction won't store the result until stage 5 and therefore the second instruction can't start fetching the results. How would you wait for the cycle to finish by inserting NOP instructions?
Instruction Cycle 1 2 3 4 5 6 7
mov $10, %eax IF ID EX MEM WB
add $2, %eax IF ID EX MEM WB
mov $4, %ebx IF ID EX MEM WB
Edit Not sure if this right but here is what I came up with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
mov $10, %eax F D E M W
NOP F D E M W
NOP F D E M W
NOP F D E M W
add $2, %eax F D E M W
mov $4, %ebx F D E M W
mov $5, %ecx F D E M W
NOP F D E M W
NOP F D E M W
add $1, %ebx F D E M W
add $1, %ecx F D E M W
NOP F D E M W
NOP F D E M W
NOP F D E M W
add %ecx, %eax F D E M W
add %ebx, %eax F D E M W