IMPLEMENTATION OF PASS OF A DIRECT LINKING LOADER
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 10
struct estab
{
char csect[10],sym_name[10];
long int add;
int length;
}table[MAX];
void main()
{
FILE
*fp1,*fp2;
char in[10];
long int
i,count=0,start,len,loc;
clrscr();
printf("\nImplementation Of Pass1 Of A Direct Linking
Loader:");
printf("\n---------------------------------------------------\n\n");
fp1=fopen("link1in.txt","r");
fp2=fopen("link1out.txt","w");
printf("Enter the Location where the program has to be loaded:
");
scanf("%lx",&start);
fprintf(fp2,"CSECT\tSYM_NAME\tADDRESS\tLENGTH\n");
rewind(fp1);
while(!feof(fp1))
{
fscanf(fp1,"%s",in);
if(strcmp(in,"H")==0)
{
fscanf(fp1,"%s",in);
strcpy(table[count].csect,in);
strcpy(table[count].sym_name,"\0");
fscanf(fp1,"%s",in);
table[count].add=atoi(in)+start;
fscanf(fp1,"%s",in);
len=atoi(in);
table[count++].length=atoi(in);
fscanf(fp1,"%s",in);
}
if(strcmp(in,"D")==0)
{
fscanf(fp1,"%s%lx",in,&loc);
while(strcmp(in,"R")!=0)
{
strcpy(table[count].csect,"\0");
strcpy(table[count].sym_name,in);
table[count].add=loc+start;
table[count++].length=0;
fscanf(fp1,"%s%lx",in,&loc);
}
while(strcmp(in,"T")!=0)
fscanf(fp1,"%s",in);
}
if(strcmp(in,"T")==0)
while(strcmp(in,"E")!=0)
fscanf(fp1,"%s",in);
fscanf(fp1,"%s",in);
start=start+len;
}
for(i=0;i<count;i++)
fprintf(fp2,"%s\t%s\t%lx\t%d\n",table[i].csect,table[i].sym_name,table[i].add,table[i].length);
printf("\nProgram
Completed Successfully...\n");
getch();
}
OUTPUT:
Implementation Of Pass1 Of A Direct Linking Loader:
-------------------------------------------------------------------
Enter the Location where the program has to be loaded: 4000
Program Completed Successfully...
INPUT FILE:
LINK1IN.TXT
H PROGA 000000
000070
D LISTA 000040 ENDA 000054
R LISTB ENDB LISTC ENDC
T 000020 10 03201D
77100004 150014
T 000054 16 100014 15100006 00002F 100014
FFFFC0
M 000024 05 +LISTB
M 000054 06 +LISTC
M 000058 06 +ENDC
M 000064 06 +LISTB
E 000000
H PROGB 000000 000088
D LISTB 000060 ENDB 000070
R LISTA ENDA
LISTC ENDC
T 000036 11 03100000 772027 05100000
T 000070 18 100000 05100006 05100020 05100030 100000
M 000037 05 +LISTA
M 000044 05 +ENDA
M 000070 06 +ENDA
M 000074 06 +ENDC
M 000078 06 +ENDC
M 000082 06 +ENDA
E 000000
H PROGC 000000 000057
D LISTC 000030 ENDC 000042
R LISTA ENDA LISTB ENDB
T 000018 12 03100000
77100004 05100000
T 000042
15 100030 100008 100011 100000 100000
M 000019
05 +LISTA
M 000023 05 +LISTB
M 000027 05 +ENDA
M 000048 06 +LISTA
M 000051 06 +ENDA
M 000054 06 +LISTB
E 000000
OUTPUT FILE:
LINK1OUT.TXT
CSECT SYM_NAME ADDRESS LENGTH
PROGA 4000
70
LISTA 4040 0
ENDA 4054
0
PROGB 4046 88
LISTB 40a6 0
ENDB 40b6 0
PROGC 409e
57
LISTC 40ce 0
ENDC 40e0 0
No comments:
Post a Comment
Thanks for your valuable comments