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:



Post a Comment