Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Implementation of Pass One of Linking Loader

#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
#include<stdlib.h>
#include<string.h>
struct head
{
char name[30];
int len;
};
struct def_r
{
char sym_l[20];
int addr;
};
struct ref_r
{
char sym_r[20];
int no;
};

struct head d[10];


struct def_r d1[10];
struct ref_r d2[10];

fstream file;

int main()
{
int n,n1,n2;
int saa,l1;
file.open("input_dat.dat", ios::out );
cout<<"enter the no of programs \t";
cin>>n;

for (int i=0;i<n;i++)


{
cout<<"\n ENTER THE HEADER RECORD \n";
cout<<"\n\t program name \t\t"; cin>>d[i].name;
cout<<"\t lenth \t\t\t"; cin>>d[i].len;
file.write((char *)&d[i],sizeof(d[i]));

cout<<"\nENTER THE DEFINITION RECORD \n";


cout<<"\n\t Variable name \t\t"; cin>>d1[i].sym_l;
cout<<"\t relative address \t"; cin>>d1[i].addr;
file.write((char *)&d1[i],sizeof(d1[i]));

cout<<"\n ENTER THE REFERENCE RECORD \n";


cout<<"\n\t variable name \t\t"; cin>>d2[i].sym_r;
cout<<"\t numeric equivalent\t"; cin>>d2[i].no;
file.write((char *)&d2[i],sizeof(d2[i]));
}
cout<<"\n INPUT \n";
file.open("input_dat.dat", ios::in );
file.seekg(0);

for ( i =0;i<n;i++)
{
file.read((char *)&d[i],sizeof(d[i]));
cout<<"H\^"
<<d[i].name
<<"\^";
cout<<d[i].len
<<"\n";
file.read((char *)&d1[i],sizeof(d1[i]));
cout<<"D\^"
<<d1[i].sym_l
<<"\^";
cout<<d1[i].addr
<<"\n";
file.read((char *)&d2[i],sizeof(d2[i]));
cout<<"R\^"
<<d2[i].sym_r
<<"\^" ;
cout<<d2[i].no
<<"\n\n";

}
file.close();
cout<<"\n enter the starting absolute address of object code \t";
cin>>saa;
cout<<"\nOUTPUT EXTERNAL SYMBOL TABLE \n"
<<"symbol_name\taddress\n"
<<"******\t\t********\n";
file.open("input_dat.dat", ios::in );
file.seekg(0);
for ( i=0;i<n;i++)
{
file.read((char *)&d[i],sizeof(d[i]));
l1=d[i].len;
file.read((char *)&d1[i],sizeof(d1[i]));
cout<<d1[i].sym_l;
cout<<"\t\t"<<d1[i].addr+saa<<"\n";
saa=saa+l1;
file.read((char *)&d2[i],sizeof(d2[i]));
}
file.close();

return 0;
}
Direct linking loader PASS 1
enter the no of programs 2

ENTER THE HEADER RECORD


program name p1
lenth 74

ENTER THE DEFINITION RECORD


Variable name a1
relative address 60

ENTER THE REFERENCE RECORD


variable name b1
numeric equivalent 1

ENTER THE HEADER RECORD


program name p1
lenth 85

ENTER THE DEFINITION RECORD


Variable name b1
relative address 54

ENTER THE REFERENCE RECORD


variable name a1
numeric equivalent 1

INPUT
H^p1^74
D^a1^60
R^b1^1

H^p2^85
D^b1^54
R^a1^1
enter the starting absolute address of object code 4000

OUTPUT EXTERNAL SYMBOL TABLE


symbol_name address
****** ********
a1 4060
b1 4128

You might also like