linker

16
LINKER

Upload: satyamevjayte-haxor

Post on 14-Jun-2015

163 views

Category:

Software


3 download

DESCRIPTION

A Complete description about linker

TRANSCRIPT

Page 1: Linker

LINKER

Page 2: Linker

What Is Linker ?combines two or more separate object programs and supplies the information needed to allow references between them

Page 3: Linker

Role of linker

Source

Program AssemblerObject

ProgramLinker

Executable Code

Loader

Object program ready for execution

Memory

Page 4: Linker

Program

Input :

1. P1.txt

extern x, y, z

2. P2.txt200 int x201 int y202 int z

Page 5: Linker

// 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];

Page 6: Linker

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");

Page 7: Linker

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);

Page 8: Linker

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;

}

Page 9: Linker

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

Page 10: Linker

}if(flag1==1) // For Digits{

b[h]='\0';strcpy(r[y].f,b);y++;h=0;u++; //counter

}}

}while(c!=EOF);h=0;

Page 11: Linker

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++;

} }

Page 12: Linker

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;

Page 13: Linker

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++;

}

Page 14: Linker

}fclose(p1);fclose(p2);getch();

}

Page 15: Linker

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

Page 16: Linker

THANK YOU..!!!