AIM:
To write a C program to implement absolute loader.
ALGORITHM:
STEP 1: Start the program execution.
STEP 2: Get the header record.
STEP 3: Get the text record.
STEP 4: Get the end record.
STEP 5: Display the program name.
STEP 6: Display the starting address.
STEP 7: Display the program length.
STEP 8: Display the text address.
STEP 9: Stop the program execution.
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
{
FILE *myfile;
int i=0,f=0,f1=0,j,k;
char ch,fn[30],stadd[15],textrec[80];
clrscr();
myfile=fopen("in.txt","r");
if(myfile == NULL)
{
puts("Cannot open the file");
exit(0);
}
while((!feof(myfile)) && f1==0)
{
while(f1==0)
{
ch = fgetc(myfile);
if((ch=='H' || ch=='h' ) && f==0)
f=1;
if(ch=='-')
{
f1=1;
break;
}
if(ch != 'H' && f==1 && f1==0)
{
fn[i]=ch;
i++;
fn[i]='\0';
}
}
if(f1==1)
for(j=0;j<=12;j++)
stadd[j]=(ch=fgetc(myfile));
stadd[j]='\0';
while(!feof(myfile))
{ ch=fgetc(myfile);
if(ch=='T')
for(k=1;k<=80;k++)
textrec[k]=(ch=fgetc(myfile));
textrec[k]='\0';
}
}
printf("Program name is %s \n",fn);
printf("\n Starting Address ");
for(i=0;i<=5;i++)
printf("%c",stadd[i]);
printf("\n Length of the Program ");
for(i=7;i<=12;i++)
printf("%c",stadd[i]);
printf("\n \n Text Address %s \n",textrec);
for(i=1;i<=80;i++)
{
if((i%7)!=0)
printf("%c",textrec[i]);
else
printf("\n");
}
getch();
}
OUTPUT:
Input
IN.TXT
HCOPY-001000-00107A
T001000-141033-482039-001036-281030-301015-482061-00102D
001000
Output
Program name is COPY
Starting address 1000
Length of the Program 00107A
Text Address
001000
141033
482039
001036
281030
301015
482061
00102D
001000
0 comments:
Post a Comment