Friday 28 September 2012

Relocating Loader in System Software - Anna University Lab Experiment No 7

Ex:7 Relocating loader

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void main()
{
int i,progadr,addr,len,stadr;
char type[1],name[10];
FILE *fp1,*fp2;
clrscr();
fp1=fopen("reip.txt","r");
fp2=fopen("reop.txt","w");
printf("Enter the PROGADDR:");
scanf("%x",&progadr);
fscanf(fp1,"%s",&type);
printf("%s",type);
if(type[0]=='H')
{
fscanf(fp1,"%s%x%d",&name,&addr,&len);
stadr=addr;
fprintf(fp2,"Program name:%s\nProgram Length:%d\nProgram Starting
Addr:%x",name,len,addr);
fprintf(fp2,"\nPROGADDR:%x",progadr);
fprintf(fp2,"\nNow Text Record Translation Begins");
while(type[0]!='M')
{
fscanf(fp1,"%s",&type);
if(type[0]=='T')
{
fscanf(fp1,"%x",&addr);
fprintf(fp2,"\nText record translated to:%x",addr+progadr);}}
fprintf(fp2,"\nNow Modification Record Translation Begins");
while(type[0]!='E')
{
fscanf(fp1,"%s",&type);
if(type[0]=='M')
{
fscanf(fp1,"%x",&addr);
fprintf(fp2,"\nModification Record Translated to:%x %s",addr+progadr,name);
}}}
getch();
}

Output:

Enter the PROGADDR:5000

H

C:\TC\BIN>type reip.txt

H COPY 001000 001077

T 001000 13

T 001020 03

M 000015 18+HCOPY

M 000017 20+HCOPY

E 000000

C:\TC\BIN>type reop.txt

Program name:COPY

Program Length:1077

Program Starting Addr:1000

PROGADDR:5000

Now Text Record Translation Begins

Text record translated to:6000

Text record translated to:6020

Now Modification Record Translation Begins

Modification Record Translated to:5017 COPY

C:\TC\BIN>exit

No comments:

Don't You Think this Awesome Post should be shared ??
| Relocating Loader in System Software - Anna University Lab Experiment No 7 |
Back To Top Related Posts Plugin for WordPress, Blogger...