# How can I build an dependency table to prevent NOPS

Good morning.

At the moment I try to understand pipelining of an MIPS processor. I know that, if I have a piece of Code and one instruction depends on the other, than we maybe could a have problem (data hazard etc.).

Now I am in a position to understated how I can solve this problem with NOPS. But I want do solve this problem with as less Nops I can. So I have to swap the lines of the code and there should be a method to see which line I have to swap, calls "dependency table". Could someone tell me how I can create such an table?

For example I have the following Code and a solution.

Code:

1 add $$t1 ,$$t2 , $$t3 2 sub$$t4 , $$t2 ,$$t5
3 or $$t6 ,$$t1 , $$t4 4 and$$t7 , $$t8 ,$$t9
5 lw $$t9 , 4($$t7 )
6 sub $$t2 ,$$t1 , $$t3 7 lw$$t1 , 16( $t9 )  Solution with nops: 1 add $$t1 ,$$t2 , $$t3 2 sub$$t4 , $$t2 ,$$t5 3 NOP 4 NOP 5 or $$t6 ,$$t1 , $$t4 6 and$$t7 , $$t8 ,$$t9 7 NOP 8 NOP 9 lw $$t9 , 4($$t7 ) 10 sub $$t2 ,$$t1 , $$t3 11 NOP 12 lw$$t1 , 16($t9 )


Solution without nops (Where this table is used):

and $$t7 ,$$t8 , $$t9 add$$t1 , $$t2 ,$$t3
sub $$t4 ,$$t2 , $$t5 lw$$t9 , 4( $$t7 ) sub$$t2 , $$t1 ,$$t3
or $$t6 ,$$t1 , $$t4 lw$$t1 , 16( \$t9 )


I know there are better solucions, but we have to try, to play MIPS Pipelined Prozessor without Forwarding Unit and Hazard Detection, it is just theory:).

Could someone tell me how i can build this dependency table, or some other tricks to solve this Code-Swap problem in a fast and save way?