Java Code For Direct Linking Loader(DLL)

Java Code For Direct Linking Loader(DLL)














//ALP program1//
PG1 START        0
ENTRY A,B
EXTRN PG2,C
.
.
.
A DC    F             20
B DC    F            30
DS A(A)            40
DS A(B+15)        44
DS A(C-PG2)        48
END                52

//ALP program2 //
PG2 START        0
ENTRY C
EXTRN A,B
C DC F            16
DS A(C+25)        20
DS A(A)            24
DS A(B+15)        28
END                32

// Java code for DLL//
import java.util.*;
import java.io.*;
class DLL
{
public static void main(String args[])
{
String sym[]=new String[50];
String type[]=new String[50];
int id[]=new int[50];
int eid[]=new int[50];
int eid1[]=new int[50];
String flag[]=new String[50];
String flag1[]=new String[50];
String sym1[]=new String[50];
String rea[]=new String[50];
String rea1[]=new String[50];
String type1[]=new String[50],l="",l1="";
String ra[]=new String[50];
String ra1[]=new String[50];
int id1[]=new int[50],l2=0,l3=0;
int c=0,d=0,e=1,k=0,fla=0,fla1=0,ctr=0,ctr1=0;
int f=0,g=0,h=1,m=0,w=0,v=0,u=0;
String a[]=new String[50];
Scanner src=new Scanner(System.in);
//System.out.println("Enter the name of 1st file with format");
//String f=src.next();
try
{
    FileReader fr=new FileReader("PG1.txt");
    BufferedReader br = new BufferedReader(fr);
    String x,y;
    while((x=br.readLine())!=null)
    {
        if(x.contains("START"))
        {
            int p=x.indexOf("START");
            sym[c++]=x.substring(0,p);
            type[d]="SD";
            id[d]=e++;
            d++;w++;
            int p1=x.lastIndexOf("\t");
            ra[k++]=x.substring(p1+1,x.length());
        }
        else if(x.contains("ENTRY"))
        {
            int p=x.indexOf(" ");
            y=x.substring(p+1,x.length());
            int p2=0;
            a=y.split(",");
            for(int i=0;i<a.length;i++)
            {
                sym[c++]=a[i];
                type[d]="LD";
                d++;w++;
                eid[v++]=1;
            }
        }
        else if(x.contains("EXTRN"))
        {
            int p=x.indexOf(" ");
            y=x.substring(p+1,x.length());
            int p2=0;
            a=y.split(",");
            for(int i=0;i<a.length;i++)
            {
                sym[c++]=a[i];
                type[d]="ER";
                id[d]=e;
                eid[v++]=e;
                d++;e++;
            }
        }
        else if(x.contains("END"))
        {
            int p=x.lastIndexOf("\t");
            l=x.substring(p+1,x.length());
            l2=Integer.parseInt(l);
        }
        else
        {
            for(int i=1;i<c;i++)
            {
                if(x.contains(sym[i]+" DC"))
                {
                    int p1=x.lastIndexOf("\t");
                    ra[k++]=x.substring(p1+1,x.length());

                }
                if(x.contains("("+sym[i])||x.contains("+"+sym[i]))
                {
                    flag[fla++]="+ve";
                    int p=x.lastIndexOf("\t");
                    rea[ctr++]=x.substring(p+1,x.length());

                }
                else if(x.contains("-"+sym[i]))
                {
                    flag[fla++]="-ve";
                    int p=x.lastIndexOf("\t");
                    rea[ctr++]=x.substring(p+1,x.length());
                }
            }
        }
    }
    for(int i=0;i<c;i++)
    {
        if (ra[i] == null)
            {
                ra[i] = "-";
            }
    }
    //System.out.println("Enter the name of 2nd file with format");
    //String fr=src.next();

    FileReader fir=new FileReader("PG2.txt");
    BufferedReader bur = new BufferedReader(fir);
    while((x=bur.readLine())!=null)
    {
        if(x.contains("START"))
        {
            int p=x.indexOf("START");
            sym1[f++]=x.substring(0,p);
            type1[g]="SD";
            id1[g]=h++;
            g++;
            int p1=x.lastIndexOf("\t");
            ra1[m++]=x.substring(p1+1,x.length());
        }
        else if(x.contains("ENTRY"))
        {
            int p=x.indexOf(" ");
            y=x.substring(p+1,x.length());
            int p2=0;
            a=y.split(",");
            for(int i=0;i<a.length;i++)
            {
                sym1[f++]=a[i];
                type1[g]="LD";
                g++;
                eid1[u++]=1;
            }
        }
        else if(x.contains("EXTRN"))
        {
            int p=x.indexOf(" ");
            y=x.substring(p+1,x.length());
            int p2=0;
            a=y.split(",");
            for(int i=0;i<a.length;i++)
            {
                sym1[f++]=a[i];
                type1[g]="ER";
                id1[g]=h;
                eid1[u++]=h;
                g++;h++;
            }
        }
        else if(x.contains("END"))
        {
            int p=x.lastIndexOf("\t");
            l1=x.substring(p+1,x.length());
            l3=Integer.parseInt(l1);
        }
        else
        {
            for(int i=1;i<f;i++)
            {
                if(x.contains(sym1[i]+" DC"))
                {
                    int p1=x.lastIndexOf("\t");
                    ra1[m++]=x.substring(p1+1,x.length());

                }
                if(x.contains("("+sym1[i])||x.contains("+"+sym1[i]))
                {   
                    flag1[fla1++]="+ve";
                    int p=x.lastIndexOf("\t");
                    rea1[ctr1++]=x.substring(p+1,x.length());
                }
                else if(x.contains("-"+sym1[i]))
                {
                    flag1[fla1++]="-ve";
                    int p=x.lastIndexOf("\t");
                    rea1[ctr1++]=x.substring(p+1,x.length());
                }
            }
        }

    }
    for(int i=0;i<f;i++)
    {
        if (ra1[i] == null)
            {
                ra1[i] = "-";
            }
    }
}
catch(Exception ex){}
System.out.println("ESD1");
System.out.println("Symbol\tType\tID\tRelative Add\tlength");
for(int i=0;i<c;i++)
{
    if(i==0)
    System.out.println(sym[i]+"\t"+type[i]+"\t"+id[i]+"\t"+ra[i]+"\t\t"+(l2+1));
    else
    System.out.println(sym[i]+"\t"+type[i]+"\t"+id[i]+"\t"+ra[i]+"\t\t-");
}
System.out.println("\n\nRLD1");
System.out.println("ESD_ID\tlength\tFlag\tRelative Add");
for(int i=0;i<v;i++)
{
    if(type[i+1].contains("ER"))
    System.out.println(eid[i]+"\t-\t"+flag[i]+"\t"+rea[i]);
    else
    System.out.println(eid[i]+"\t4\t"+flag[i]+"\t"+rea[i]);
}

System.out.println("\n\nESD2");
System.out.println("Symbol\tType\tID\tRelative Add\tlength");
for(int i=0;i<f;i++)
{
    if(i==0)
    System.out.println(sym1[i]+"\t"+type1[i]+"\t"+id1[i]+"\t"+ra1[i]+"\t\t"+(l3+1));
    else
    System.out.println(sym1[i]+"\t"+type1[i]+"\t"+id1[i]+"\t"+ra1[i]+"\t\t-");
}


System.out.println("\n\nRLD2");
System.out.println("ESD_ID\tlength\tFlag\tRelative Add");
for(int i=0;i<u;i++)
{
    if(type1[i+1].contains("ER"))
    System.out.println(eid1[i]+"\t-\t"+flag1[i]+"\t"+rea1[i]);
    else
    System.out.println(eid1[i]+"\t4\t"+flag1[i]+"\t"+rea1[i]);
}


System.out.println("\n\nEnter value for IPLA ");
int z=src.nextInt();
int y[]=new int[50];
int y1[]=new int[50];

try
{
for(int i=0;i<k;i++)
    y[i]=Integer.parseInt(ra[i].trim());
}
catch (Exception exc){}
try
{
for(int i=0;i<m;i++)
    y1[i]=Integer.parseInt(ra1[i].trim());
}
catch (Exception exc){}
for(int i=0;i<m;i++)
    System.out.println(y1[i]);

System.out.println("GEST");
System.out.println("Symbol\tAddress");
u=0;
for(int i=0;i<c;i++)
{
    if(type[i].contains("ER"))
    {
        System.out.println(sym[i]+"\t"+(z+y1[u++]+l2+1));
    }
    else
    System.out.println(sym[i]+"\t"+(z+y[i]));
}

}
}


0 comments :