IMPLEMENTATION OF A RELOCATION LOADER | URDINESH

Software Programming, Tutorials, Interview Preparations,Stock Market,BSE/NSE, General informations

Wednesday, May 7, 2014

IMPLEMENTATION OF A RELOCATION LOADER

IMPLEMENTATION OF A RELOCATION LOADER

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
struct object_code
{
   int locctr; char add[10];
}obcode[300];
void main()
{
   char in[100][16],out[100][16],bin[20],addr[20],stloc[10];
   int len,bitmask,loc,tlen=0,tloc,textloc,i=0,location,j,k,count=0,start,n,num=0,inc=0;
   FILE *fp1,*fp2;
   clrscr();
   printf("\nImplementation Of A Relocation Loader:");
   printf("\n--------------------------------------\n\n");
   fp1=fopen("loadin.txt","r");
   fp2=fopen("loadout1.txt","w");
   printf("Enter the Location where the program has to be loaded : ");
   scanf("%s",stloc);
   start=atoi(stloc);
   location=start;
   tloc=start;
   fscanf(fp1,"%s",in[i]);
   while(strcmp(in[i],"T")!=0)
   {
     strcpy(out[i],in[i]); i++;
     fscanf(fp1,"%s",in[i]);
     strcpy(out[i],in[i]);
   }
   itoa(start,out[2],10);
   while(strcmp(in[i],"E")!=0)
   {
     strcpy(out[i],in[i]);
     if(strcmp(in[i],"T")==0)
     {
       for(j=0;j<3;j++)
       {
             i++;
             fscanf(fp1,"%s",in[i]);
             strcpy(out[i],in[i]);
       }
       bitmask=atoi(out[i]);
       itoa(bitmask,bin,2);
       strcpy(out[i],NULL);
       textloc=atoi(out[i-2]);
       textloc=textloc+start;
       itoa(textloc,out[i-2],10);
       for(n=0;n<(textloc-(tloc+tlen));n++)
       {
             strcpy(obcode[inc].add,"XX");
             obcode[inc++].locctr=location++;
       }
       tlen=atoi(out[i-1]);
       tloc=textloc; k=0;
     }
     else
     {
       if(bin[k]=='1')
       {
             num=0; len=strlen(out[i]);
             strcpy(addr,NULL);
             for(j=2;j<len;j++)
             {
               addr[num]=out[i][j];
               out[i][j]='\0';
               num++;
             }
             loc=atoi(addr); loc=loc+start;
             itoa(loc,addr,10);
             strcat(out[i],addr);
       }
       k++;
       len=strlen(out[i]); num=0;
       for(n=0;n<len;n++)
       {
             obcode[inc].add[num++]=out[i][n];
             if(num>1)
             {
               obcode[inc++].locctr=location++;
               num=0;
             }
       }
     }
     i++;
     fscanf(fp1,"%s",in[i]);
   }
   strcpy(out[i],in[i]); i++;
   fscanf(fp1,"%s",in[i]);
   loc=atoi(in[i]); loc=loc+start;
   strcpy(out[i],itoa(loc,addr,10));
   count=0; i=0; n=0;
   fprintf(fp2,"%d\t",obcode[n].locctr);
   for(n=0;n<inc;n++)
   {
     fprintf(fp2,"%s",obcode[n].add);
     i++;
     if(i>3)
     {
       fprintf(fp2,"\t");
       i=0; count++;
     }
     if(count>3)
     {
       fprintf(fp2,"\n%d\t",obcode[n+1].locctr);
       count=0;
     }
   }
   printf("\nProgram Completed Successfully...\n");
   getch();
}























OUTPUT:


Implementation Of A Relocation Loader:
----------------------------------------------------

Enter the Location where the program has to be loaded : 6000

Program Completed Successfully...



INPUT FILE:


LOADIN.TXT

H    PROG1    000000    000018
T    000000   15    000009    180012    0C0015   000005    000010
T    000023   18    000034    200029    130043    0C0054   000006    00015
E    000000



OUTPUT FILE:


LOADOUT1.TXT

6000    1860120C              00150000      05006010      XXXXXXXX        
6016    XXXXXXXX        20602913      00430C00    54000006    

6032    006015

No comments:

Post a Comment

Thanks for your valuable comments

Followers