Assume: R1 = 12, R2=192, R3=48, R4=1, R5=2, R6=3, R7=4
add r1, r2, r3 // R1 = R2 + R3
// Old value = 12 = 00000000 00001100
// New value = 240 = 00000000 11110000 (visually easy to distiguish)
add r4, r1, r4 // R4 = R1 + R4
add r4, r1, r5 // R5 = R1 + R5
add r4, r1, r6 // R6 = R1 + R6
add r4, r1, r7 // R7 = R1 + R7
...
|
Also, at start of the CPU cycle, the ID stage selects R4 and R1 (!!!) to be copied into the "A" and "B" registers:
|
Therefore: an old (= wrong !!) value 12 of register R1 will be fetched and used in the add r4, r1, r4 instruction execution !!!
Also, at the end of the CPU cycle, "A" is updated to R4 (=1) and "B" is updated to the value in R1 (= 12 !!!). This value is a wrong value because R1 should be updated with the new value (= 240) !!
Also, at the end of the CPU cycle, the instruction (add r1, r2, r3) is moved into IR(MEM), "add r4, r1, r4" is moved into IR(EX) and instruction "add r5, r1, r5" is fetched into IR(ID)
Also, at start of the CPU cycle, the ID stage selects R1 and the OLD value of R1 will also be copied into the "B" register (because register R1 has not yet been updated with the new value !!!):
Also, at the end of the CPU cycle, "A" register is updated to R5 and "B" register is updated to the old (= wrong !) value of R1 .
Also, at the end of the CPU cycle, the instruction (add r1, r2, r3) is moved into IR(WB), "add r4, r1, r4" is moved into IR(MEM), instruction "add r5, r1, r5" is moved into IR(EX) and instruction "add r6, r1, r6" is fetched into IR(ID)
|
Recall that:
|
|
I put the timing in the picture (see the clock signal)
(because the general purpose registers - of which R1 is one of them - are updated when clock signal goes from 0-->1)
So a little (time) after the midpoint (but before the transition from 1-->0), the new value 240 of R1 will arrive at register B:
/home/cs355001/demo/pipeline/4a-ALU-hazard Executes this program: 10 12 // mov r1,#12 18 192 // mov r2,#192 26 48 // mov r3,#48 34 1 // mov r4,#1 42 2 // mov r5,#2 50 3 // mov r6,#3 58 4 // mov r7,#4 0 0 // nop 0 0 // nop 0 0 // nop 0 0 // nop 8 19 // add r1,r2,r3 (R1=R2+R3) 32 33 // add r4,r1,r4 (R4 = R1 + R4) ** These instructions 40 41 // add r5,r1,r5 (R5 = R1 + R5) ** will use an old value 48 49 // add r6,r1,r6 (R6 = R1 + R6) 56 57 // add r7,r1,r7 (R7 = R1 + R7) |
What to do:
|