Page 141 - DCAP507_SYSTEM_SOFTWARE
P. 141

Unit 9: Design of an Absolute Loader




                                                                                                Notes
                 Example: Write a C program to execute pass 1 of direct linking loader.
          #include<stdio.h>
          #include<conio.h>
          #include<stdlib.h>
          #include<string.h>
          #define  MAX  10
          struct  estab
          {        char  csect[10];
          char  sym_name[10];
          long  int  add;
          int  length;
          }table[MAX];
          void  main()
          {      FILE  *fp1,  *fp2;
          char  input[10];
          long  int  i,  count  =0,  start,  length,  loc;
          clrscr();
          fp1=fopen("linkin.dat",  "r");
          fp2=fopen("linkout.dat",  "w");
          printf("Enter  the  location  where  the  program  has  to  be  loaded:");
          scanf("%lx",  &start);
          fprintf(fp2,  "CSECT  \t  symname  \t  address  \t  length\n");
          rewind(fp1);
          while(!feof(fp1))
          {
          fscanf(fp1,  "%s",  input);
          if(strcmp(input,  "H")==0)
          {
          fscanf(fp1,  "%s",  input);
          strcpy(table[count].csect,  input);
          strcpy(table[count].sym_name,  "");
          fscanf(fp1,  "%s",  input);
          table[count].add=atoi(input)+start;
          fscanf(fp1,  "%s",  input);
          length=atoi(input);
          table[count++].length=atoi(input);
          fscanf(fp1,  "%s",  input);
          }
          if(strcmp(input,  "D")==0)




                                           LOVELY PROFESSIONAL UNIVERSITY                                   135
   136   137   138   139   140   141   142   143   144   145   146