Your Ad Here

Tuesday, August 25, 2009

Two Pass Assembler

#include< stdio.h>
#include< conio.h>
#include< string.h>
#define lines_in_program 9
void print(char *p,int loc,int len,char ra)
{printf("%s\t%d\t%d\t%c\n",p,loc,len,ra);}
void main()
{
char *p[9][4] = {{"PRG1","START","",""},{"","USING","*","15"},
{"","L","1","FIVE"}, {"","A","1","FOUR"},
{"","ST","1","TEMP"}, {"FOUR","DC","F'4'",""},
{"FIVE","DC","F'5'",""}, {"TEMP","DS","1F",""},
{"","END","",""}};
int i,j=0,location_counter=0;
clrscr();
for (i=0;i< 9;i++)
{ for(j=0;j< 4;j++)
printf("%s\t",p[i][j]);
printf("\n");
}
printf("\n\n\n\n Symbol ");
printf("Table:\nSYMBOL\tVALUE\tLENGTH\tRelocatable/Absolute\n");
printf("---------------------------------------------\n");
for(i=0;i< 9;i++)
{ if(strcmp(p[i][1],"START")==0)
print(p[i][0],location_counter,1,'R');
else if(strcmp(p[i][0],"")!=0)
{
print(p[i][0],location_counter,4,'R');
location_counter=4+location_counter;
}
else if(strcmp(p[i][1],"USING")==0){}
else{location_counter=4+location_counter;}
}
getch();
}


/*OUTPUT:
PRG1 START
USING * 15
L 1 FIVE
A 1 FOUR
ST 1 TEMP
FOUR DC F'4'
FIVE DC F'5'
TEMP DS 1F
END

Symbol Table:
SYMBOL VALUE LENGTH Relocatable/Absolute
---------------------------------------------
PRG1 0 1 R
FOUR 12 4 R
FIVE 16 4 R
TEMP 20 4 R */

2 comments:

Anonymous said...
This comment has been removed by a blog administrator.
C Programs with output said...

Free C programs with output, c programming language, object oriented programming, c programs codes, c program shortcuts, history of c programming language, c programming compilers

Your Ad Here