New Member FAQ | Forums | Earn Revenue


Resources Entrance Ask Experts Exam Papers Jobs English Projects Universities Colleges Courses Schools Training My India



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



ASS 1 OF AN TWO PASS ASSEMBLER


Posted Date:     Total Responses: 0    Posted By: R V Vinod Babu   Member Level: Silver   Points/Cash: 7   


#include
#include
#include
struct a
{
char b[10][10];
};
struct a source[10];
struct a symtab[10];
struct a littab[10];
struct a opcode[10];
struct a reg[10];
FILE *f1,*f2,*f3,*f4,*f5,*f6;
int litcount,litlines,vari,prolines,w,x,symlines,reglines,oplines,loc;
void main ()
{
int i,k=0,j;
char ch;
f1=fopen("source2.txt","r");
f2=fopen("symtab1.txt","w");
f3=fopen("opcodes.txt","r");
f5=fopen("literal.txt","w");
f4=fopen("register.txt","r");
f6=fopen("out2pass1.txt","w");
clrscr();
printf("\n source program \n");
while(!feof(f1))
{
for(i=0;i<4;i++)
{
fscanf(f1,"%s",&source[k].b[i]);
printf("%s",source[k].b[i]);
printf("\t");
}
printf("\n");
k++;
}
prolines=k;
getch();
clrscr();
loc=atoi(source[0].b[3]);
j=0;
printf("\n SYMBOL TABLE\n");
printf("SI.NO\tSYMBOL\tADDRESS\n");
for(i=0;i<12;i++)
{
if(strcmp(source[i].b[0],"*")!=0)
{
j++;
fprintf(f2,"%d\t%s\t%d",j,source[i].b[0],(loc+i)+1);
printf("%d\t%s\t%d",j,source[i].b[0],(loc+i)+1);
printf("\n");
fprintf(f2,"\n");
}
}
getch();
clrscr();
k=0;
printf("\n register table\n");
while(!feof(f4))
{
for(i=0;i<2;i++)
{
fscanf(f4,"%s",®[k].b[i]);
printf("%s",reg[k].b[i]);
printf("\t");
}
printf("\n");
k++;
}
reglines=k;
getch();
clrscr();
k=0;
loc=atoi(source[0].b[3]);
for(i=0;i<10;i++)
if(strcmp(source[i].b[1],"LTORG")==0)
litcount=loc+i+1;
//printf("%d",litcount);
printf("\nliteral table\n");//literal table generation
//printf("%s",source[7].b[1]);
k=1;
for(i=1;i<=10;i++)
if(source[i].b[3][0]=='=')
{
fprintf(f5,"%d\t%s\t%d",k,source[i].b[3],litcount);
printf("%d\t%s\t%d",k,source[i].b[3],litcount);
k++;
litcount++;
printf("\n");
}
litlines=k-1;
getch();
clrscr();
k=0;
printf("\n opcode table\n");
while(!feof(f3))
{
for(i=0;i<2;i++)
{
fscanf(f3,"%s",&opcode[k].b[i]);
printf("%s",opcode[k].b[i]);
printf("\t");
}
printf("\n");
k++;
}
oplines=k;
getch();
clrscr();
k=0;
fclose(f5);
f5=fopen("literal.txt","r");
while(!feof(f5))
{
for(i=0;i<3;i++)
{
fscanf(f5,"%s",&littab[k].b[i]);
}
k++;
}
fclose(f1);
fclose(f2);
fclose(f3);
fclose(f4);
fclose(f5);
f2=fopen("symtab1.txt","r");
k=0;
while(!feof(f2)) //creation of symbol table struct
{
for(i=0;i<3;i++)
{
fscanf(f2,"%s",&symtab[k].b[i]);
}
k++;
}
symlines=k;
fclose(f2);
printf("\nintermediate code \n");
fprintf(f6,"\nINTERMEDIATE CODE \n");
ch=source[10].b[2][0];
//printf("%s",source[8].b[1]);
//printf("\n%s",source[9].b[1]);
//printf("\n%s",source[10].b[1]);
prolines=prolines-2;
printf("(AD,00)\t\t(C,%s)\n",source[0].b[3]);
fprintf(f6,"(AD,00)\t\t(C,%s)\n",source[0].b[3]);
for(i=1;i<=prolines;i++)//starting the creation of intermediate code
{
w=x=0;
if(strcmp(source[i].b[1],"DS")!=0 && strcmp(source[i].b[1],"DC")!=0 )
{
for(j=0;j<10;j++)
if(strcmp(source[i].b[1],opcode[j].b[0])==0)
{
//vari=atoi(opcode[j].b[1]);
printf("(IM,%s)\t",opcode[j].b[1]);
fprintf(f6,"(IM,%s)\t",opcode[j].b[1]);
}
}
if(strcmp(source[i].b[1],"DS")==0 || strcmp(source[i].b[1] ,"DC")==0 )
{
for(j=0;j<10;j++)
if(strcmp(source[i].b[1],opcode[j].b[0])==0)
{
//vari=atoi(opcode[j].b[1]);
printf("(DL,%s)\t",opcode[j].b[1]);
fprintf(f6,"(DL,%s)\t",opcode[j].b[1]);
}
} //finish of first column
for(j=0;j<4;j++)
{
if(strcmp(source[i].b[2],reg[j].b[0])==0)
{
w=1;
printf("(%s)\t",reg[j].b[1]);
fprintf(f6,"(%s)\t",reg[j].b[1]);
}
}//finish of third column
if(source[i].b[2][0]==ch) //where ch=" ' "
{
x=1;
printf("\t(C,%c)\t",source[i].b[2][1]);
fprintf(f6,"\t(C,%c)\t",source[i].b[2][1]);
}
if(w!=1 && x!=1 && strcmp(source[i].b[1],"LTORG")!=0)
{
printf("\t");
fprintf(f6,"\t");
}
for(j=0;j<3;j++)
if(strcmp(source[i].b[3],symtab[j].b[1])==0)
{
printf("(S,%d)",atoi(symtab[j].b[0]));
fprintf(f6,"(S,%d)",atoi(symtab[j].b[0]));
}
if(source[i].b[3][0]=='=')
for(j=0;jif(strcmp(source[i].b[3],littab[j].b[1])==0)
{
printf("(L,%s)",littab[j].b[0]);
fprintf(f6,"(L,%s)",littab[j].b[0]);
}
if(strcmp(source[i].b[1],"LTORG")!=0)
{
printf("\n");
fprintf(f6, "\n");
}
}
printf("(AD,03)");
fprintf(f6,"(AD,03)");
getch();
}



Project Feedbacks


No feedbacks found. Be the first to respond and make money from revenue sharing program.

Post Feedback
You must Sign In to post a feedback.
Next Project: PASS 1 OF AN TWO PASS ASSEMBLER
Previous Project: Pass 2 of 2 pass assembler

Return to Project Index

Post New Project


Related Projects



Advertise Here





Contact Us   Advertise   Editors    Privacy Policy    Terms Of Use   

ISC Technologies.
2006 - 2009 All Rights Reserved.