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



//CREATION OF SINGLE PASS ASSEMBLER//


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


//CREATION OF SINGLE PASS ASSEMBLER//
#include
#include
#include
struct a
{
char b[10][10];
}source[10];
struct a symtab[10];
struct a reg[10];
struct a opcode[10];
FILE *f1,*f2,*f3,*f4;
int prolines,reglines,oplines,symlines,loc;
void main ()
{
int i,h,k=0,x,y,j,w;
char ch;
f1=fopen("source1.txt","r");
f2=fopen("register.txt","r");
f3=fopen("opcodes.txt","r");
f4=fopen("symbol.txt","w");
clrscr();
printf("\n the 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++;
}
getch();
clrscr();
prolines=k;
k=0;
printf("\n register table\n");
while(!feof(f2))
{
for(i=0;i<2;i++)
{
fscanf(f2,"%s",®[k].b[i]);
printf("%s",reg[k].b[i]);
printf("\t");
}
printf("\n");
k++;
}
getch();
clrscr();
reglines=k;
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++;
}
getch();
clrscr();
oplines=k;
loc=atoi(source[0].b[3]);
printf("\nsymbol table\n");
for(i=0;i<10;i++)
{
if(strcmp(source[i].b[0],"*")!=0)
{
fprintf(f4,"%s\t%d\n",source[i].b[0],(loc+i)-1);
printf("%s\t%d\n",source[i].b[0],(loc+i)-1);
}
printf("\n");
fprintf(f4,"\n");
}
getch();
clrscr();
fclose(f1);
fclose(f2);
fclose(f3);
fclose(f4);
f4=fopen("symbol.txt","r");
k=0;
while(!feof(f4)) //creation of symbol table struct
{
for(i=0;i<2;i++)
{
fscanf(f4,"%s",&symtab[k].b[i]);
}
k++;
}
symlines=k;
printf("the assembeled code is \n");
prolines=prolines-2;//except start and end
ch=source[7].b[2][0];
for(i=1;i{
w=x=y=h=0;
printf("%d\t+\t",(loc+i)-1); //printing 1st col
for(j=0;j{
if(strcmp(opcode[j].b[0],source[i].b[1])==0)
{
printf("%d\t",atoi(opcode[j].b[1])); //printing opcode
h=1;
}
}
if(h!=1)
printf("0\t");
if(source[i].b[2][0]==ch)
{
w=1;
printf("0\t%c",source[i].b[2][1]);
}
for(j=0;j{
if(strcmp(reg[j].b[0],source[i].b[2])==0)
{ //printing reg number
printf("%d\t",atoi(reg[j].b[1]));
x=1;
}
}
if(x!=1 && w!=1)
printf("0\t");
for(j=0;j{
if(strcmp(symtab[j].b[0],source[i].b[3])==0)
{
printf("%d",atoi(symtab[j].b[1]));
y=1;
}
}
if(y!=1&&w!=1)
printf("000");
printf("\n");
}
fclose(f4);
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: //macro pass2//
Previous Project: //program relocation//

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.