import java.util.*;
class datahazard
{
static void accept()
{
Scanner scr=new Scanner(System.in);
System.out.print("\nFirst Instruction:\nOpcode ");
s[0][0]=scr.nextLine();
System.out.print("\nDomain: ");
s[0][2]=scr.nextLine();
System.out.print("\nRange: ");
s[0][1]=scr.nextLine();
System.out.print("\nSecond Instruction:\nOpcode ");
s[1][0]=scr.nextLine();
System.out.print("\nDomain: ");
s[1][2]=scr.nextLine();
System.out.print("\nRange: ");
s[1][1]=scr.nextLine();
}
static int check()
{
if(s[0][1].equals(s[1][2]))
return 1;
else
if(s[0][2].equals(s[1][1]))
return 2;
else
if(s[0][1].equals(s[1][1]))
return 3;
else
return 0;
}
static String s[][]=new String[2][3];
public static void main(String args[])
{
Scanner scr=new Scanner(System.in);
int ch=0;
do
{
int c=0;
accept();
System.out.println(s[0][0]+" "+s[0][1]+" "+s[0][2]);
System.out.println(s[1][0]+" "+s[1][1]+" "+s[1][2]);
c=check();
if(c==1)
System.out.println("RAW hazard exists");
else
if(c==2)
System.out.println("WAR hazard exists");
else
if(c==3)
System.out.println("WAW hazard exists");
else
System.out.println("There are No Data Dependency Hazards");
System.out.println("Do you wish to continue?(1/0)");
ch=scr.nextInt();
}
while(ch==1);
}
}
Output:
D:\Extras>javac datahazard.java
D:\Extras>java datahazard
First Instruction:
Opcode mul
Domain: r2
Range: r1
Second Instruction:
Opcode add
Domain: r4
Range: r1
mul r1 r2
add r1 r4
WAW hazard exists
Do you wish to continue?(1/0)
1
First Instruction:
Opcode mov
Domain: r2
Range: m2
Second Instruction:
Opcode mov
Domain: r1
Range: m1
mov m2 r2
mov m1 r1
There are No Data Dependency Hazards
Do you wish to continue?(1/0)
0
D:\Extras>
class datahazard
{
static void accept()
{
Scanner scr=new Scanner(System.in);
System.out.print("\nFirst Instruction:\nOpcode ");
s[0][0]=scr.nextLine();
System.out.print("\nDomain: ");
s[0][2]=scr.nextLine();
System.out.print("\nRange: ");
s[0][1]=scr.nextLine();
System.out.print("\nSecond Instruction:\nOpcode ");
s[1][0]=scr.nextLine();
System.out.print("\nDomain: ");
s[1][2]=scr.nextLine();
System.out.print("\nRange: ");
s[1][1]=scr.nextLine();
}
static int check()
{
if(s[0][1].equals(s[1][2]))
return 1;
else
if(s[0][2].equals(s[1][1]))
return 2;
else
if(s[0][1].equals(s[1][1]))
return 3;
else
return 0;
}
static String s[][]=new String[2][3];
public static void main(String args[])
{
Scanner scr=new Scanner(System.in);
int ch=0;
do
{
int c=0;
accept();
System.out.println(s[0][0]+" "+s[0][1]+" "+s[0][2]);
System.out.println(s[1][0]+" "+s[1][1]+" "+s[1][2]);
c=check();
if(c==1)
System.out.println("RAW hazard exists");
else
if(c==2)
System.out.println("WAR hazard exists");
else
if(c==3)
System.out.println("WAW hazard exists");
else
System.out.println("There are No Data Dependency Hazards");
System.out.println("Do you wish to continue?(1/0)");
ch=scr.nextInt();
}
while(ch==1);
}
}
Output:
D:\Extras>javac datahazard.java
D:\Extras>java datahazard
First Instruction:
Opcode mul
Domain: r2
Range: r1
Second Instruction:
Opcode add
Domain: r4
Range: r1
mul r1 r2
add r1 r4
WAW hazard exists
Do you wish to continue?(1/0)
1
First Instruction:
Opcode mov
Domain: r2
Range: m2
Second Instruction:
Opcode mov
Domain: r1
Range: m1
mov m2 r2
mov m1 r1
There are No Data Dependency Hazards
Do you wish to continue?(1/0)
0
D:\Extras>