IMPLEMENTATION OF PASS 1 OF A LINKING LOADER

Aim
To perform pass one the Linking loader using c program in CS1207 SYSTEM SOFTWARE LAB
Algorithm
Star the program for linking loader
Assign the necessary variable and the header variable
Open the two file
In fp1 for link input file for read privilege
And fp2 for load map file for write privilege
Read the character until the input is not equal to END
And the check the character in if condition input is H then
Get the name from fp1
Copy the name between csname=name
And extsym=**
Else if the character is D
Then get the input variable
In these if condition perform the while loop the read character until the input is not equal to R
The copy csnmae=**
And extsym=input
Then add address =add+csaddr
And length is equal to zero
And perform the operation (see the Source code)
Finally terminate the program

Source code in c program performing passes one linking loader
# include <stdio.h>
# include <conio.h>
# include <string.h>
# define MAX 20
struct estab
{
char csname[10];
char extsym[10];
int address;
int length;
}es[MAX];
void main()
{
char input[10],name[10],symbol[10];
int count=0,progaddr,csaddr,add,len;
FILE *fp1,*fp2;
clrscr();
fp1=fopen("linkinput.dat","r");
fp2=fopen("loadmap.dat","w");
printf("Enter the location where the program has to be loaded : ");
scanf("%d",&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,"%d",&add);
es[count].address=add+csaddr;
fscanf(fp1,"%d",&len);
es[count].length=len;
fprintf(fp2,"%s\t%s\t\t%d\t%d\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,"%d",&add);
// printf("CSADDR = %d",csaddr);
es[count].address=add+csaddr;
es[count].length=0;
fprintf(fp2,"%s\t%s\t\t%d\t%d\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,"--------------------------------------\n");
fclose(fp1);
fclose(fp2);
printf("FINISHED\n");
getch();
}



INPUT FILE :
LINKINPUT.DAT
H PROGA 0000 1000
D LISTA 0040 ENDA 0054
R LISTB ENDB LISTC ENDC
T 0020 141033 465555 678909 568787 345678
T 0054 000014 789087 776555 876666 456666
M 0054 06 +LISTC
E 0000

H PROGB 0000 2000
D LISTB 0040 ENDB 0054
R LISTA ENDA LISTC ENDC
T 0020 141033 465555 678909 568787 345678
T 0054 000000 789087 776555 876666 456666
M 0054 06 +ENDA
M 0054 06 -LISTA
M 0054 06 +LISTC
E 0000

H PROGC 0000 3000
D LISTC 0040 ENDC 0054
R LISTA ENDA LISTC ENDB
T 0020 141033 465555 678909 568787 345678
T 0054 000020 789087 776555 876666 456666
M 0054 06 +ENDA
M 0054 06 -LISTA
M 0054 06 +PROGC
E 0000
END



OUTPUT:
Enter the location where the program has to be loaded : 5000
LOADMAP.DAT
CS_NAME EXT_SYM_NAME ADDRESS LENGTH
------------------------------------------------
PROGA ** 5000 1000
** LISTA 5040 0
** ENDA 5054 0
PROGB ** 6000 2000
** LISTB 6040 0
** ENDB 6054 0
PROGC ** 8000 3000
** LISTC 8040 0
** ENDC 8054 0
------------------------------------------------



Post a Comment

0 Comments