import java.util.*;
/***************************************
* AMP Pracs-1
* --------------------------------------------------
* TITLE : SuperScalar Architecture
* -------------------------------------------------
* Simulate U & V pipelines
* of Pentium processor
*
* @author Rohit Iyer 09-221
* SEM-6 Vidyalankar Institute of Technology
* Mumbai University
*
* @date 28/01/2012
****************************************/
class PipelineExp
{
public static void main(String args[]) throws Exception
{
Scanner src=new Scanner(System.in);
System.out.println("Enter no of instructions:");
int n=src.nextInt();
int U[]=new int[4];
int V[]=new int[4];
int umax,vmax;
if(n%2==1)
{
umax=n;
vmax=n-1;
}
else
{
vmax=n;
umax=n-1;
}
int x=n;
if(n%2==1)
x=x+1;
x=((x-2)/2)+5;
int j=1;
for(int i=1;i<=x;i++)
{
U[3]=U[2];
U[2]=U[1];
U[1]=U[0];
U[0]=j++;
V[3]=V[2];
V[2]=V[1];
V[1]=V[0];
V[0]=j++;
for(int k=0;k<4;k++)
{
if(U[k]>umax)
U[k]=0;
if(V[k]>vmax)
V[k]=0;
}
System.out.println("\n\nPipeline U status\n\n");
if(U[0]!=0)
System.out.println("Fetch Stage: I"+U[0]);
if(U[1]!=0)
System.out.println("Decode Stage: I"+U[1]);
if(U[2]!=0)
System.out.println("Execute Stage: I"+U[2]);
if(U[3]!=0)
System.out.println("WriteBack Stage: I"+U[3]);
System.out.println("\n\nPipeline V status\n\n");
if(V[0]!=0)
System.out.println("Fetch Stage: I"+V[0]);
if(V[1]!=0)
System.out.println("Decode Stage: I"+V[1]);
if(V[2]!=0)
System.out.println("Execute Stage: I"+V[2]);
if(V[3]!=0)
System.out.println("WriteBack Stage: I"+V[3]);
System.in.read();
}
}
}

No comments:
Post a Comment