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

Ss

Uploaded by

dabahe4893
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Ss

Uploaded by

dabahe4893
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

#include<stdio.

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;
printf("Enter the actual starting address : ");
scanf("%x",&start);
fp1=fopen("RLIN1.txt","r");
fp2=fopen("RLOUT.txt","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,"%s",add);
fscanf(fp1,"%s",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");
fclose(fp1);
fclose(fp2);
printf("\n\n The contents of output file(RLOUT.TXT\n");
fp2=fopen("RLOUT.txt","r");
ch=fgetc(fp2);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp2);
}
fclose(fp2);

}
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;
}
}
}
#include<stdio.h>
#include<string.h>
struct DEFTAB
{
char opcode[10];
char operand[50];
}dt[50];
struct NAMTAB
{
char name[10];
int start;
int end;
}nt[5];
struct ARGTAB
{
char arg[10];
}at[5];
struct PARAMTAB
{
char param[10];
char val[4];
}pt[5];
int n,p,m,g;
int check_param(char x[40])
{
int i;
for(i=0;i<p;i++)
if(strcmp(pt[i].param,x)==0)
return i;
return -1;
}
int check_macro(char x[20])
{
int i;
for(i=0;i<m;i++)
if(strcmp(nt[i].name,x)==0)
return i;
return -1;
}
void store()
{
FILE *f,*fp;
int k,i,j;
char a[20],b[20],c[40],temp[20],lab[20];
n=0;p=0;m=0;g=0;
f=fopen("INPUT.txt","r");
fp=fopen("exp.txt","w");
while(!feof(f))
{
fscanf(f,"%s\t%s\t%s\n",a,b,c);
if(strcmp(b,"MACRO")==0)
{
strcpy(nt[m].name,a);
nt[m].start=0;

k=1;
j=0;
i=0;
while(c[i]!='\0')
{
if(c[i]!=',')
{
temp[j]=c[i];
j++;
}
else
{
temp[j]='\0';
j=0;
strcpy(pt[p].param,temp);
pt[p].val[0]='?';
pt[p].val[1]=p+49;
pt[p].val[2]='\0';
p++;
}
i++;
}
temp[j]='\0';
strcpy(pt[p].param,temp);
pt[p].val[0]='?';
pt[p].val[1]=p+49;
pt[p].val[2]='\0';
p++;
strcpy(dt[n].opcode,b);
strcpy(dt[n].operand,c);
n++;
}
else if(k==1)
{
i=check_param(c);
strcpy(dt[n].opcode,b);
if(i==-1)
strcpy(dt[n].operand,c);
else
strcpy(dt[n].operand,pt[i].val);
n++;
if(strcmp(b,"MEND")==0)
{
k=0;
nt[m].end=n-1;
m++;
}
}
else if((check_macro(b))!=-1)
{
i=0;
g=0;
j=0;
while(c[i]!='\0')
{
if(c[i]!=',')
{
temp[j]=c[i];
j++;
}

else
{
temp[j]='\0';
j=0;
strcpy(at[g].arg,temp);
g++;
}
i++;
}
temp[j]='\0';
strcpy(at[g].arg,temp);
g++;
strcpy(a,"NULL");
for(i=1;i<n-1;i++)
{
if(dt[i].operand[0]=='?')
{
j=dt[i].operand[1]-49;
strcpy(temp,at[j].arg);
}
else
strcpy(temp,dt[i].operand);
fprintf(fp,"%s\t%s\t%s\n",a,dt[i].opcode,temp);
}
}
else
fprintf(fp,"%s\t%s\t%s\n",a,b,c);
}
fclose(f);
fclose(fp);
}
int main()
{
int i;
store();
printf("\n DEFTAB:\n");
for(i=0;i<n;i++)
printf("%s\t%s\n",dt[i].opcode,dt[i].operand);
printf("\n NAMETAB:\nNAME\tSTART\tEND\n");
for(i=0;i<m;i++)
printf("%s\t%d\t%d\n",nt[i].name,nt[i].start,nt[i].end);
printf("\n ARGTAB: \nPosition\tArgument\n");
for(i=0;i<g;i++)
printf("%d\t\t%s\n",i+1,at[i].arg);
}

You might also like