Sei sulla pagina 1di 4

IMPLEMENTATION OF PASS TWO OF DIRECT LINKING LOADER

AIM:
To write a C program to implement pass two of direct linking loader.
ALGORITHM:
STEP 1: Start the program execution.
STEP 2: Find the control section length from the header record.
STEP 3: In the text record, character form is converted to machine representation.
STEP 4: Move the object code from record to memory location.
STEP 5: In the modification record, search for symbol to be modified from external table.
If found symbol address is added or subtracted with corresponding symbol address
and value at starting location.
STEP 6: Stop the program execution.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
struct obj
{
char rec[20],sym[10],addr[20];
}ob;
struct estab
{
char sym[20];
int addr;
}es;
void main()
{
FILE *f1,*f2;
int csaddr,maddr,cslth,addr;
clrscr();
f1=fopen("OBJ.TXT","r");
f2=fopen("ESTAB.TXT","r");
fscanf(f2,"%s%d",es.sym,&es.addr);
csaddr=es.addr;
printf("memoryaddr object code\n");
while(!feof(f1))
{
fscanf(f1,"%s%s%s",ob.rec,ob.sym,ob.addr);
cslth=atoi(ob.addr);
while(strcmp(ob.rec,"E")!=0)

{
int s;
fscanf(f1,"%s%s%s",ob.rec,ob.sym,ob.addr);
if(strcmp(ob.rec,"T")==0)
{
addr=csaddr+atoi(ob.sym);
s=atoi(ob.addr);
printf("%d\t%s\n",addr,ob.addr);
}
if(strcmp(ob.rec,"M")==0)
{
maddr=csaddr+atoi(ob.sym);
while(!feof(f2))
{
fscanf(f2,"%s%d",es.sym,&es.addr);
if(strcmp(ob.addr,es.sym)==0)
{
es.addr=es.addr+s;
printf("%d\t%d\n",maddr,es.addr);
break;
}}
rewind(f2);
}
}
csaddr+=cslth;
}
fcloseall();
getch();
}

INPUT:
OBJ.TXT FILE:

ESTAB.TXT FILE:

OUTPUT:

RESULT:
Thus the above program pass-2 of direct link loading was executed and output was
verified successfully.

Potrebbero piacerti anche