0% found this document useful (0 votes)
2 views2 pages

Relocating Loader: Experiment Name: Experiment No.: Date: Compiler: Filename

Uploaded by

sanjaikv536
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Relocating Loader: Experiment Name: Experiment No.: Date: Compiler: Filename

Uploaded by

sanjaikv536
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Experiment Name: RELOCATING LOADER

Experiment No. : 11 Date : 16-11-23


Compiler : gcc Filename : Load.c
Aim : To the Implementation of relocating loader.

PROGRAM

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char length[10],input[10],binary[12],bitmask[12],relocbit;
int start,inp,len,i,address,opcode,addr,actualadd,add;
FILE *fp1,*fp2;
printf("Enter the actual starting address:");
scanf("%d",&start);
fp1=fopen("[Link]","r");
fp2=fopen("[Link]","w");
fscanf(fp1,"%s",input);
while(strcmp(input,"E")!=0)
{
if(strcmp(input,"H")==0)
{
fscanf(fp1,"%d",&add);
fscanf(fp1,"%s",length);
fscanf(fp1,"%s",input);
start-=add;
}
if(strcmp(input,"T")==0)
{
fscanf(fp1,"%d",&address);
fscanf(fp1,"%s",bitmask);
address+=start;
len=strlen(bitmask);
for(i=0;i<len;i++)
{
fscanf(fp1,"%d",&opcode);
fscanf(fp1,"%d",&addr);
relocbit=bitmask[i];
if(relocbit=='0')
actualadd=addr;
else
actualadd=addr+start;
fprintf(fp2,"%d\t%d%d\n",address,opcode,actualadd);
address+=3;
}
fscanf(fp1,"%s",input);
}
}
fclose(fp1);
fclose(fp2);
printf("finished");
}

OUTPUT

[Link]

[Link]

You might also like