AIM:
To write a C program to implement pass one of direct linking loader.
ALGORITHM:
STEP 1: Start the program execution.
STEP 2: Enter the location when the program has to be loaded.
STEP 3: Assign the address got from the user as the first control section address.
STEP 4: Read the loader record of control section.
STEP 5: Enter the symbol into the symbol table with address and also with control
section address
STEP 6: Address of the control section and control section length together is the starting
address of next control section.
STEP 7: Stop the program execution.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<stdlib.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("link1in.c","r");
fp2=fopen("file1.c","w");
printf("Enter the location where the program has to be loaded");
scanf("%lx",&start);
fprintf(fp2,"CSECT\t\tSYMNAME\t\tADDRESS\tLENGTH\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,"\0");
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)
{
fscanf(fp1,"%s%lx",input,&loc);
while((strcmp(input,"R")!=0))
{s
trcpy(table[count].csect,"\0");
strcpy(table[count].sym_name,input);
table[count].add=loc+start;
table[count++].length=0;
fscanf(fp1,"%s%lx",input,&loc);
}
while(strcmp(input,"T")!=0)
fscanf(fp1,"%s",input);
} if(strcmp(input,"T")==0)
while(strcmp(input,"E")!=0)
fscanf(fp1,"%s",input);
fscanf(fp1,"%s",input);
start=start+length;
}
for(i=0;i<count;i++)
fprintf(fp2,"%s\t\t%s\t\t%lx\t\t
%d\n",table[i].csect,table[i].sym_name,table[i].add,table[i].length);
getch();
}
0 comments:
Post a Comment