linker
DESCRIPTION
A Complete description about linkerTRANSCRIPT
LINKER
What Is Linker ?combines two or more separate object programs and supplies the information needed to allow references between them
Role of linker
Source
Program AssemblerObject
ProgramLinker
Executable Code
Loader
Object program ready for execution
Memory
Program
Input :
1. P1.txt
extern x, y, z
2. P2.txt200 int x201 int y202 int z
// SIMULATION OF LINKER#include<iostream.h>#include<conio.h>#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>
struct x{
char f[10];
}s[20],t[20],r[10];
void main(){
clrscr();x o[2]={"int","float"};x z[20],v[20];char c,*a,*b;int i=0, j=0, k=0, l=0, flag=0, flag1=0,
h=0, y=0, u=0; int m;
FILE *p1,*p2;p1=fopen("p1.txt","r");p2=fopen("p2.txt","r");
do{
c=fgetc(p1);if(c!=' '&&c!='\n'&&c!=','){
a[i]=c;i++;
}else{
a[i]='\0';strcpy(s[j].f,a);j++;i=0;k++; }
}while(c!=EOF);
i=0;j=0;do{
c=fgetc(p2);if(c!=' '&& c!='\n'){
if((abs(c)>=65&&abs(c)<=90)||(abs(c)>=97&&abs(c)<=122))
{a[i]=c; //insert characters
e.g.int xi++;flag=1;
}
else{
b[h]=c; //insert digits e.g. 200
h++;flag1=1;
}}else{
if(flag==1) //For characters{
a[i]='\0';strcpy(t[j].f,a);j++;i=0; l++; //counter
}if(flag1==1) // For Digits{
b[h]='\0';strcpy(r[y].f,b);y++;h=0;u++; //counter
}}
}while(c!=EOF);h=0;
for(i=0;i<l;i++){
flag=0;for(j=0;j<2;j++) //for characters{if(strcmp(t[i].f,o[j].f)==0||
strcmp(t[i].f,"")==0){
flag=1;}
}if(flag==0){
strcpy(v[h].f,t[i].f);h++;
} }
l=0;for(i=0;i<u;i++) //for digits{
if(strcmp(r[i].f,"")!=0){
strcpy(z[l].f,r[i].f);l++;
}}cout<<"\n********After Linking*********\
n";flag=0;l=0;
for(i=0;i<k;i++){
flag=0;for(j=0;j<h;j++){
if(strcmp(s[i].f,v[j].f)==0)flag=1;
}if(flag==1){
m=atoi(z[l].f)+400;cout<<s[i].f<<" "<<"p1"<<"
"<<m<<"\n";l++;
}
}fclose(p1);fclose(p2);getch();
}
P1.txtextern x, y, z;
P2.txt 200 int x201 int y202 int z
After Linking x p1 600 y p1 601 z p1 602
THANK YOU..!!!