affiliate marketing

Saturday 17 December 2011

PASS1 OF DIRECT LINKING LOADER


PROGRAM:
#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 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 FILES:
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:

No comments:

Post a Comment