C Program for the Implementation of a Relocating Loader | CS1207 - System Software Laboratory

AIM:
             To write a "C" program for the implementation of Relocating Loader in CS1207 - System Software Lab.

SOURCE CODE:

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void convert(char h[12]);
char bitmask[12];
char bit[12]={0};
void main()
{char add[6],length[10],input[10],binary[12],relocbit,ch,pn[5];
int start,inp,len,i,address,opcode,addr,actualadd,tlen;
FILE *fp1,*fp2;
clrscr();
printf("\n\n Enter the actual starting address : ");
scanf("%x",&start);
fp1=fopen("RLIN.DAT","r");
fp2=fopen("RLOUT.DAT","w");
fscanf(fp1,"%s",input);
fprintf(fp2," ----------------------------\n");
fprintf(fp2," ADDRESS\tCONTENT\n");
fprintf(fp2," ----------------------------\n");
while(strcmp(input,"E")!=0)
{
if(strcmp(input,"H")==0)
{
fscanf(fp1,"%s",pn);
fscanf(fp1,"%x",add);
fscanf(fp1,"%x",length);
fscanf(fp1,"%s",input);
}
if(strcmp(input,"T")==0)
{
fscanf(fp1,"%x",&address);
fscanf(fp1,"%x",&tlen);
fscanf(fp1,"%s",bitmask);
address+=start;
convert(bitmask);
len=strlen(bit);
if(len>=11)
len=10;
for(i=0;i<len;i++)
{
fscanf(fp1,"%x",&opcode);
fscanf(fp1,"%x",&addr);
relocbit=bit[i];
if(relocbit=='0')
actualadd=addr;
else
actualadd=addr+start;
fprintf(fp2,"\n  %x\t\t%x%x\n",address,opcode,actualadd);
address+=3;
}
fscanf(fp1,"%s",input);
}
}
fprintf(fp2," ----------------------------\n");
fcloseall();
printf("\n\n The contents of output file (RLOUT.DAT):\n\n");
fp2=fopen("RLOUT.DAT","r");
ch=fgetc(fp2);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp2);
}
fclose(fp2);
getch();
}
void convert(char h[12])
{
int i,l;
strcpy(bit,"");
l=strlen(h);
for(i=0;i<l;i++)
{
switch(h[i])
{
case '0':
    strcat(bit,"0");
    break;
case '1':
    strcat(bit,"1");
    break;
case '2':
    strcat(bit,"10");
    break;
case '3':
    strcat(bit,"11");
    break;
case '4':
    strcat(bit,"100");
    break;
case '5':
    strcat(bit,"101");
    break;
case '6':
    strcat(bit,"110");
    break;
case '7':
    strcat(bit,"111");
    break;
case '8':
    strcat(bit,"1000");
    break;
case '9':
    strcat(bit,"1001");
    break;
case 'A':
    strcat(bit,"1010");
    break;
case 'B':
    strcat(bit,"1011");
    break;
case 'C':
    strcat(bit,"1100");
    break;
case 'D':
    strcat(bit,"1101");
    break;
case 'E':
    strcat(bit,"1110");
    break;
case 'F':
    strcat(bit,"1111");
    break;
}
}
}

INPUT FILE:

RLIN.DAT
H COPY 001000 00107A
T 001000 1E FFC 14 0033 48 1039 10 0036 28 0030 30 0015 48 1061 3C 0003 20 002A 1C 0039 30 002D
T 002500 15 E00 1D 0036 48 1061 18 0033 4C 1000 80 1000 60 1003
E 000000

OUTPUT:

Related Posts:
  • IMPLEMENTATION OF A SYMBOL TABLE
  • IMPLEMENTATION OF A RELOCATING LOADER
Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: