0% found this document useful (0 votes)
31 views

Implementation of Relocation Loader Formated

This document contains code for a relocation loader that takes a binary file with relocation bits as input. It reads the input file, applies any base address offsets from the header, and writes an output file with the addresses adjusted based on the relocation bits and the actual starting address provided. The code opens input and output files, reads records with opcodes and addresses from the input file, applies relocation by checking bits and adding the starting address offset if needed, and writes adjusted records to the output file.

Uploaded by

prabuknoble
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Implementation of Relocation Loader Formated

This document contains code for a relocation loader that takes a binary file with relocation bits as input. It reads the input file, applies any base address offsets from the header, and writes an output file with the addresses adjusted based on the relocation bits and the actual starting address provided. The code opens input and output files, reads records with opcodes and addresses from the input file, applies relocation by checking bits and adding the starting address offset if needed, and writes adjusted records to the output file.

Uploaded by

prabuknoble
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

/* Implementation of Relocation Loader */

# include <stdio.h>
# include <conio.h>
# include <stdlib.h>
# include <string.h>
void main()
{
char add[6],length[10],input[10],binary[12],bitmask[12],relocbit;
int start,inp,len,i,address,opcode,addr,actualadd;
FILE *fp1,*fp2;
clrscr();
printf("\n Enter the actual starting address : ");
scanf("%d",&start);
fp1=fopen("relinput.dat","r");
fp2=fopen("reloutput.dat","w");
fscanf(fp1,"%s",input);
while(strcmp(input,"E")!=0)
{
if(strcmp(input,"H")==0)
{
fscanf(fp1,"%s",add);
fscanf(fp1,"%s",length);
fscanf(fp1,"%s",input);
start-=atoi(add);
}
if(strcmp(input,"T")==0)
{
fscanf(fp1,"%d",&address);
fscanf(fp1,"%s",bitmask);
address+=start;
len=strlen(bitmask);
for(i=0;i
{
fscanf(fp1,"%d",&opcode);
fscanf(fp1,"%d",&addr);
relocbit=bitmask[i];
if(relocbit=='0')
actualadd=addr;
else
actualadd=addr+start;
fprintf(fp2," %d\t%d%d\n",address,opcode,actualadd);
printf(" %d\t%d%d\n",address,opcode,actualadd);
address+=3;
}

fscanf(fp1,"%s",input);
}
}
fclose(fp1);
fclose(fp2);
printf(" \n FINISHED");
getch();
}

OUTPUT :
INPUT FILE : RELINPUT.DAT
H 1000 200
T 1000 11001 14 1033 48 1039 90 1776 92 1765 57 1765
T 2011 11110 23 1838 43 1979 89 1060 66 1849 99 1477
E 1000
SCREEN OUTPUT :
Enter the actual starting address :4000
4000 144033
4003 484039
4006 901776
4009 921765
4012 574765
5011 234838
5014 434979
5017 894060
5020 664849
5023 991477
FINISHED
OUTPUT FILE : RELOUTPUT.DAT
4000 144033
4003 484039
4006 901776
4009 921765
4012 574765
5011 234838
5014 434979
5017 894060
5020 664849
5023 991477

You might also like