You are on page 1of 2

Aim: To Write a C program to Implement a Relocation Loader. Algorithm: Step1:Open The Source Program in the read only mode.

Step2: Scan the header Program to record from the source file. Step3: Until the end of the source file do the Following a)Scan the next input line from the source program. b)Compare the first string and if it is a text record do the following i)Get the LOCATION COUNTER value from the user ii)Calculate the difference of the selecting address of the source program and location counter value iii)Load the Object Code into memory,location that is relative to the selecting location specified by the user iv)Repeat this process links and of text record PROGRAM: #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<string.h> int main() { char a[12],b[12],c[12],d[100],f[100]; long int len,i,j=0,o,x,t,k,e,g,temp,addr; long int loc,loc2; FILE *p1; clrscr(); p1=fopen("input.c","r"); printf("\nRELOACTION LOADER"); printf("\nEnter the Relocation Address : "); scanf("%d",&loc); loc2=loc; while(!feof(p1)) { t=0; x=6; fscanf(p1,"%s%s%s%s",a,b,c,d); if((strcmp(a,"H")==0)||(strcmp(a,"E")==0)) printf("\n"); else {

e=0; g=0; len=strlen(d); for(i=0;i<(len/6);i++) { printf("\n\t%d\t",loc); for(j=t+2,k=0;j<x;k++,j++) f[k]=d[j]; for(i=e;i<g;i++) printf("%c",d[i]); e+=6; g+=6; addr=atoi(f); temp=temp=loc2+addr; printf("00%d",temp); loc+=3; t+=6; x+=6; } } } fcloseall(); getch(); return 0; } SAMPLE INPUT FILE: H T T E Copy 1000 12 0000 6 001111002222 0000 6 003333004444 0000

You might also like