Absolute&Relocatable
Absolute&Relocatable
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char input[10];
int start,length,address;
FILE *fp1,*fp2;
clrscr();
fp1=fopen("INPUT.DAT","r");
fp2=fopen("OUTPU.DAT","w");
fscanf(fp1,"%s",input);
while(strcmp(input,"E")!=0)
{
if(strcmp(input,"H")==0)
{
fscanf(fp1,"%d",&start);
fscanf(fp1,"%d",&length);
fscanf(fp1,"%s",input);
}
else if(strcmp(input,"T")==0)
{
fscanf(fp1,"%d",&address);
fscanf(fp1,"%s",input);
fprintf(fp2,"%d\t%c%c\n",address,input[0],input[1]);
fprintf(fp2,"%d\t%c%c\n",(address+1),input[2],input[3]);
fprintf(fp2,"%d\t%c%c\n",(address+2),input[4],input[5]);
address+=3;
fscanf(fp1,"%s",input);
}
else
{
fprintf(fp2,"%d\t%c%c\n",address,input[0],input[1]);
fprintf(fp2,"%d\t%c%c\n",(address+1),input[2],input[3]);
fprintf(fp2,"%d\t%c%c\n",(address+2),input[4],input[5]);
address+=3;
fscanf(fp1,"%s",input);
}
}
fclose(fp1);
fclose(fp2);
printf("finished");
getch();
}
Input.Dat
H 1000 323
T 1000 142033 483039 102036
T 2000 298300 230000 302015
E
Output.Dat
1000
1001
1002
1003
1004
1005
1006
1007
1008
2000
2001
2002
2003
2004
2005
2006
2007
2008
14
20
33
48
30
39
10
20
36
29
83
00
23
00
00
30
20
15
PROGRAM(Relocatable Loader)
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
void main()
{
char h[5],name[45],type[3],sh[879];
int addr,len1,i=0,sta,sta1,val,sta2,w;
int code,len;
FILE *f1,*f2;
clrscr();
f1=fopen("inn.dat","r");
f2=fopen("final.dat","w");
fscanf(f1,"%s %s %x %x",h,name,&sta,&len);
fscanf(f1,"%s",type);
printf("Enter the starting address\n");
scanf("%x",&addr);
fscanf(f1,"%x %x %x %x",&sta1,&len1,&w,&code);
sta2=sta1+addr;
for(i=(len1)/2;i>0;i--)
{
fprintf(f2,"%x %x\n",sta2,w);
val=code+addr;
sta2++;
fprintf(f2,"%x %x\n",sta2,val);
sta2++;
fscanf(f1,"%x %x",&w,&code);
}
fclose(f1);
fclose(f2);
getch();
}
Input.Dat
H COPY 000000 00001B
T 000000 12 14 0015 02 0018 0C 001B 02 0012 0C 0018 08 0015
E 000000
Output.Dat
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
300a
300b
300c
300d
300e
300f
3010
3011
14
3015
2
3018
c
301b
2
3012
c
3018
8
3015
e
3000
e
3000
e
3000