Information Technology Reference
In-Depth Information
I 1
I 2
I 3
I 4
I 5
I 6
I 7
I 8
I 9
I 10
IS
IE
ID
IF
Nop Nop Nop
Nop Nop Nop
Nop Nop Nop
Nop Nop Nop
I 2
I 10
I 1
I 3
I 4
I 5
I 6
I 7
I 8
I 9
I 1
I 2
I 3
I 4
I 5
I 6
I 7
I 8
I 9
I 10
I 1
I 2
I 3
I 4
I 5
I 6
I 7
I 8
I 9
I 10
123456789012 4
13
15
16
Figure 9.8 The use of NOP instructions
In order to execute this set of instructions while preventing the fetching of the
wrong instruction, we assume that a specified number of NOP instructions have
been inserted such that they follow instruction I 4 in the sequence and they precede
instruction I 5 . Figure 9.8 shows the Gantt's chart illustrating the execution of the
new sequence of instructions (after inserting the NOP instructions). The figure
shows that the insertion of THREE NOP instructions after instruction I 4 will guar-
antee that the correct instruction to fetch after I 4 , in this case I 5 , will only be fetched
during time slot number 8 at which the result of executing I 4 would have been stored
and the condition for the branch would have been known.
It should be noted that the number of NOP instructions needed is equal to (n 2
1),
where n is the number of pipeline stages.
Example 4 illustrates the use of NOP instructions to prevent fetching the wrong
instruction in the case of instruction dependency. A similar approach can be used to
prevent fetching the wrong operand in the case of data dependency. Consider the
execution of the following piece of code on a five-stage pipeline (IF, ID, OF, IE, IS).
ADD R 1 , R 2 , R 3 ;
R 3 R 1 þ R 2
SUB
R 3 ,1,R 4 ;
R 4 R 3 2
1
MOV R 5 , R 6 ;
R 6 R 5
Note the data dependency in the form of read-after-write (R-W) between the first
two instructions. Fetching the operand for the second instruction, that is, fetching
the content of R 3 , cannot proceed until the result of the first instruction has been
stored. In order to achieve that, NOP instructions can be inserted between the first
two instructions as shown below.
ADD R 1 , R 2 , R 3 ;
R 3 R 1 þ R 2
NOP
NOP
SUB
R 3 ,1,R 4 ;
R 4 R 3 2
1
R 6 R 5
MOV R 5 , R 6 ;
Execution of the modified sequence of instructions is shown in Figure 9.9. The
figure shows that the use of NOP guarantees that during time unit #6 instruction
Search WWH ::




Custom Search