C Program for the Implementation of a Pass One of a Direct-Linking Loader | CS1207 - System Software Laboratory



AIM:
            To write a "C" program to implement Pass one of a direct-linking loader in CS1207 - System Software Lab.


ALGORITHM:
1.Get the PROGADDR from the user
2.Initiate CSADDR with value of PROGADDR
3.Read header record from object program
4.Store the length of the control section in CSLTH
5.Search the ESTAB for control section name
(i)If found display an error message
(ii)Otherwise, insert the control section name with CSADDR into ESTAB
6.Read the next input record
7.If the record type is END goto step 10
8.If the record type is not D goto step 6
9.Search the ESTAB for symbol names given in D record.
(i)If found display an error message
(ii)Otherwise, insert the symbol into ESTAB with the sum of CSADDR and indicated address and goto step 6.
10.Add CSLTH to CSADDR.
11.If end of file is reached, Exit. Otherwise goto step 3.


SOURCE CODE:
 
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct estab
{
  char csname[10];
  char extsym[10];
  int address;
  int length;
}es[20];
void main()
{
  char input[10],name[10],symbol[10],ch;  int count=0,progaddr,csaddr,add,len;
  FILE *fp1,*fp2;
  clrscr();
  fp1=fopen("LINP.DAT","r");
  fp2=fopen("LOADMAP.DAT","w");
  printf("\n\nEnter the address where the program has to be loaded : ");
  scanf("%x",&progaddr);
  csaddr=progaddr;
  fprintf(fp2,"CS_NAME\tEXT_SYM_NAME\tADDRESS\tLENGTH\n");
  fprintf(fp2,"--------------------------------------\n");
  fscanf(fp1,"%s",input);
  while(strcmp(input,"END")!=0)
  {
   if(strcmp(input,"H")==0)
   {
    fscanf(fp1,"%s",name);
    strcpy(es[count].csname,name);
    strcpy(es[count].extsym,"  ");
    fscanf(fp1,"%x",&add);
    es[count].address=add+csaddr;
    fscanf(fp1,"%x",&len);
    es[count].length=len;
    fprintf(fp2,"%s\t%s\t\t%x\t%x\n\n",es[count].csname,es[count].extsym,es[count].address,es[count].length);
    count++;
   }
   else if(strcmp(input,"D")==0)
   {
    fscanf(fp1,"%s",input);
    while(strcmp(input,"R")!=0)
    {
     strcpy(es[count].csname,"  ");
     strcpy(es[count].extsym,input);
     fscanf(fp1,"%x",&add);
     es[count].address=add+csaddr;
     es[count].length=0;
     fprintf(fp2,"%s\t%s\t\t%x\t%x\n\n",es[count].csname,es[count].extsym,es[count].address,es[count].length);
     count++;
     fscanf(fp1,"%s",input);
    }
    csaddr=csaddr+len;
   }
   else if(strcmp(input,"T")==0)
   {
    while(strcmp(input,"E")!=0)
      fscanf(fp1,"%s",input);
   }
   fscanf(fp1,"%s",input);
  }
  fprintf(fp2,"--------------------------------------");
  fcloseall();
  printf("\n The contents of output file:\n\n");
  fp2=fopen("LOADMAP.DAT","r");
  ch=fgetc(fp2);
  while(ch!=EOF)
  {
   printf("%c",ch);
   ch=fgetc(fp2);
  }
  fclose(fp2);
  getch();
}


INPUT FILE:

LINP.DAT
H PROGA 000000 000063
D LISTA 000040 ENDA 000054
R LISTB ENDB LISTC ENDC
T 000020 141033 465555 678909 568787 345678
T 000054 000014 789087 776555 876666 456666
M 000054 06 +LISTC
E 000020

H PROGB 000000 00007F
D LISTB 000060 ENDB 000070
R LISTA ENDA LISTC ENDC
T 000036 141033 465555 678909 568787 345678
T 000070 000000 789087 776555 876666 456666
M 000054 06 +ENDA
M 000054 06 -LISTA
M 000054 06 +LISTC
E

H PROGC 000000 000051
D LISTC 000030 ENDC 000042
R LISTA ENDA LISTC ENDB
T 000018 141033 465555 678909 568787 345678
T 000042 000020 789087 776555 876666 456666
M 000054 06 +ENDA
M 000054 06 -LISTA
M 000054 06 +PROGC
E
END

OUTPUT:

Related Posts:
Previous
Next Post »

Still not found what you are looking for? Try again here.