ldr r1, [r2+r3] // R1=240, R2=4, R3=24, R4=1, R5=2, R6=3, R7=4
// Value in R1 = 240 = 00001111 00000000 (bin)
// Suppose Memory[28] = 11111111 00000000 (bin)
add r4, r1, r4 // Correct R4 = 11111111 00000001
add r5, r1, r5 // Correct R5 = 11111111 00000010
add r6, r1, r6 // Correct R4 = 11111111 00000011
add r7, r1, r7 // Correct R4 = 11111111 00000100
...
|
As you will see later:
|
Slideshow:
State of the CPU at the end of cycle 1:
![]() |
![]() |
State of the CPU at the end of cycle 2:
![]() |
![]() |
Notice that 28 is an address (in the memory), and the value must still be fetched from this memory location and then stored in register R1
Also, at start of the CPU cycle, the ID stage selects registers R4 and R1 to be fetched into the "A" and "B" registers.
|
The LOAD instruction does NOT produce a valid result for the destination register. So we enter an INVALID tag into the Tag Register of Forwarding Register 1 to prevent the value being fetched by the multiplexor.
An invalid tag is easy to formulate: suppose you have 8 registers in the CPU, just enter the value 9 or higher into the tag register or we can add one more bit in the tag register field to indicate if the tag is "valid".
Also, at the end of the CPU cycle, A is updated to R4 (=1) and B is updated to the "current value" of R1 (= 123). This "current" value is a wrong value because there is a more current one on the way from the memory....
Notice that the CPU - at this moment - does not have a clue what that "more current value of R1" is.... because the CPU must still get that value from the memory....
Also, at the end of the CPU cycle, the instruction (ldr 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)
![]() |
|
|
The following figure summarizes the situation before the instructions are executed:
![]() |
|
![]() |
|