Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

pass one of a direct-linking loader in C

"C" program to implement Pass one of a direct-linking loader
#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
  int i,j,k,pgmaddr,csaddr,cslth=0,z,addr1,l1;
  char line[50],name[10],len[10],la[10],addr[10];
  FILE *fp1;
  clrscr();
  printf("Enter the starting address\n");
  scanf("%d",&pgmaddr);
  csaddr=pgmaddr;
  for(k=0;k<2;k++)
  {
    if(k==0)
     fp1=fopen("linkin.txt","r");
if(k==1)
     fp1=fopen("linkin1.txt","r");
do
{
 fscanf(fp1,"%s",line);
if(line[0]=='H')
{
  for(i=2,j=0;i<8,j<6;i++,j++)
  name[j]=line[i];
name[j]='\0';
for(i=16,j=0;i<20,j<5;i++,j++)
 len[j]=line[i];
len[j]='\0';
cslth=atoi(len);
printf("%s\t\t%d\t%s\n",name,csaddr,len);
}
else if(line[0]=='D')
{
  i=2;
  j=0;
do
{
do
{
la[j++]=line[i++];
}while(line[i]!='^');
la[j]='\0';
j=0;i++;
do
{addr[j++]=line[i++];
} while(line[i]!='^');
i++;
addr[j]='\0';
addr1=atoi(addr)+csaddr;
j=0;
printf("%s\t\t%d\n",la,addr1);
} while(line[i]!='\0');
}
else if(line[0]=='R'||'T')
z=0;
else if(line[0]=='E')
fclose(fp1);
}while(!feof(fp1));
csaddr=csaddr+cslth;
}getch();
}






Input files:
linkin.txt
H^PROGA1^000000^0073
D^LISTA^000024^ENDA^000027^
R^LISTB
T^000000^06^000024^010027
E^000000


linkin1.txt
H^PROGA2^000000^0089
D^LISTB^000047^
E


Output:
Enter the starting address
2000
PROGA120000073
LISTA2024
ENDA2027
PROGA220730089
LISTB2120