The code below runs on a 5-stage pipelined datapath. I am having a hard time knowing whether my understanding of how pipelining works is correct or not. In my attempt below, I try to solve a data hazard in a datapath with no data forwarding unit, by inserting 'bubbles' in the oppropriate places. My first question is, is my pipelining logic below correct?
My second question is assuming there IS a forwarding unit in the datapath, from MEM->EX and from WB->EX, how would that change my logic from the first question?
add t0, s1, s2
add t1, t0, s3
sub t2, t0, t1
xor t3, t2, a0
lw t4, 0(t7)
slt t5, t4, t3
This is my attempt for question 1:
add t0, s1, s2 //IF add1 instruction
nop //ID add1 instruction
nop //EX add1 instruction
add t1, t0, s1 //MEM add1 instruction, IF add2 instruction
nop //WB add1 instruction, ID add2 instruction
nop //EX add2 instruction
nop //MEM add2 instruction
nop //WB add2 instruction
sub t2, t0, t1 //IF sub instruction
nop //ID sub instruction
nop //EX sub instruction
nop //MEM sub instruction
xor t3, t2, a0 //WB sub instruction, IF xor instruction
lw t4, 0(t7) //ID xor instruction, IF lw instruction
nop //EX xor instruction, ID lw instruction
nop //MEM xor instruction, EX lw instruction
nop //WB xor instruction, MEM lw instruction
slt t5, t4, t3 //WB lw instruction, IF slt instruction