Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » ParsingRSS Feeds

PROGRAM FOR PASS-I & PASS-II

Posted By: Isaac Evans     Category: C++ Programming     Views: 3218

PROGRAM FOR PASS-I & PASS-II.

Code for PROGRAM FOR PASS-I & PASS-II in C++ Programming

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdlib.h>
#include<ctype.h>
#include<dos.h>

class PassCode
{
    private:
            char str[120][10];
            charis[11][10];
            char reg[10][10];
            char ad[10][10];
            char dl[10][10];
            char cd[10][10];
            int I;

    public:
            PassCode();
            void getCode();
            void disCode();
            void display();
            void displaycode();
            void dispass2();
            void assum();
            void asscode();
            int check(char *);
            char temp[10],tempe[10],temp9[10][10],temp10[10][10];
            int temp1;
            char temp2[10][10],temp4[10],temp8[10];
            char temp3[10],temp5[10],temp6[10];
            char symTab[20][20];
            char litTab[20][20];
            char poolTab[20][20];
            char symadd[20][20];
            char litadd[20][20];
            char tt[10],ch1[30],loccnt[20][20];
            int i,z,x,c,t,s,a,cntr,J,r,cnt,C,err,look;
            int locptr,llocptr,symatr,litatr,symptr,litptr;
            int q,as,mn,poolptr,lcntr,cc,cha,dil,loc,tp,pt;
            char t2[10];
};
PassCode :: PassCode()
{
     I=0,i=0,cntr=0,locptr=0,symatr=0,litatr=0,symptr=0,litptr=0,C=0,tp=0,pt=0;
      err=0,q=0,as=0,mn=0,poolptr=0,lcntr=0,llocptr=0,cha=0,look=0,loc=0;
    strcpy(is[0],"STOP");
    strcpy(is[1],"ADD");
    strcpy(is[2],"SUB");
    strcpy(is[3],"MULT");
    strcpy(is[4],"MOVER");
    strcpy(is[5],"MOVEM");
    strcpy(is[6],"COMP");
    strcpy(is[7],"BC");
    strcpy(is[8],"DIV");
    strcpy(is[9],"READ");
    strcpy(is[10],"PRINT");

    strcpy(reg[0],"AREG");
    strcpy(reg[1],"BREG");
    strcpy(reg[2],"CREG");
    strcpy(reg[3],"DREG");

    strcpy(ad[0],"  ");
    strcpy(ad[1],"START");
    strcpy(ad[2],"END");
    strcpy(ad[3],"ORIGIN");
    strcpy(ad[4],"EQU");
    strcpy(ad[5],"LTORG");

    strcpy(dl[0]," ");
    strcpy(dl[1],"DC");
    strcpy(dl[2],"DS");

    strcpy(cd[0]," ");
    strcpy(cd[1],"LT");
    strcpy(cd[2],"LE");
    strcpy(cd[3],"GT");
    strcpy(cd[4],"GE");
    strcpy(cd[5],"EQ");
    strcpy(cd[6],"ANY");

}




void PassCode :: getCode()
{
      char ch,temp[10];
        cout<<endl<<"     WRITE ASSEMBLY CODE FOR PASS-I (ENDED WITH END                                KEYWORD)"<<endl;
      cout<<"     ------------------------------------------------------\n";
      while(ch!=EOF)
      {
        ch=getchar();
        if(ch!=' ' && ch!='\n' && ch!=',')
        {
           ch=toupper(ch);
           temp[i]=ch;
           i++;
        }

          else
        {
          if(ch==' ' || ch==',')
          {
            ch1[cha]=ch;
            cha++;
          }
          if(ch=='\n')
          {
            temp[i]='\0';
            strcpy(str[I],temp);
            I++;
            strcpy(str[I],"%");
            I++;
            i=0;
           }
           else
           {
             temp[i]='\0';
             strcpy(str[I],temp);
             i=0;
             I++;
            }
        }
        }
}

void PassCode :: asscode()
{
   clrscr();
   int ay=0,yah=0,lab=0,lab1=0;
   cout<<endl<<endl<<"\t\t\t";
   for(int ya=0;ya<I;ya++)
   {
    lab=0;
    if(strcmp(str[++ya],"%")==0)
    {
        yah=ya+1;
        cout<<str[--ya];
        for(int que=0;que<symatr;que++)
        {
         if(strcmp(str[yah],symTab[que])==0)
         {
              lab=1;
              lab1=1;
         }
        }

        if(lab==1)
        {
          int oo=0;
          strcpy(temp,str[yah]);
          strcat(temp,'\0');
          while(temp[oo]!='\0')
          {
            oo++;
          }
          oo--;
          oo=3-oo;
          cout<<endl<<"\t\t";
          for(int oop=0;oop<=oo;oop++)
          {
           cout<<" ";
          }
        }

        else
        {
        cout<<endl<<"\t\t\t";
        }
        ya++;
    }
    else
    {
       cout<<str[--ya];
       cout<<ch1[ay];
       ay++;
       if(lab1==1)
       {
           cout<<"  ";
       }
       lab1=0;
    }
   }
   nosound();
}
void PassCode :: disCode()
{
    int ku=0,flagg=0,kl=1;
    char tempu[10];
    J=0,loc=0;
    strcpy(tt,str[J]);
    if(strcmp(str[J],"START")==0)
    {
      locptr=atoi(str[++J]);
      strcpy(tempu,str[1]);
      while(tempu[ku]!='\0')
      {
        if(tempu[ku]>='0' && tempu[ku]<='9')
        {
        flagg=1;
        ku++;
        continue;
        }


        else
        flagg=0;
        ku++;

      }

      if(flagg==0)
      {
        err=3;
      }


      else
      {
        if(strcmp(str[2],"%")==0)
        {
        for(J=2;J<=I;J++)
        {
        dil=symatr;
        strcpy(tt,str[J]);
        C=check(str[J]);

        if(C==1)
        {
            cnt=0;

            if(strcmp(str[J],"DC")==0 || strcmp(str[J],"DS")==0)
            {
                temp1=atoi(str[++J]);
                locptr=locptr+temp1-1;
                kl=1;
            }
            elseif(strcmp(str[J],"EQU")==0)
            {
              if(kl==0)
              {
                  locptr++;
              }
              llocptr=locptr;
              strcpy(temp3,"");
              strcpy(temp4,"");
              strcpy(temp5,"");
              strcpy(temp6,"");
              strcpy(temp8,"");
              strcpy(temp2[0],str[++J]);
              strcpy(t2,temp2[0]);
              while(t2[q]!='+' && t2[q]!='-')
              {
                temp3[mn]=t2[q];
                q++;
                mn++;
              }
              temp8[0]=t2[q];
              temp8[1]='\0';
              strcpy(temp9[tp],temp8);
              tp++;
              q++;

              temp3[mn]='\0';
              strcpy(temp5,temp3);

              while(t2[q]!='\0')
              {
                temp4[as]=t2[q];
                q++;
                as++;
              }
              temp4[as]='\0';
              strcpy(temp6,temp4);
              strcpy(temp10[pt],temp6);
              pt++;
              for(int lk=0;lk<symatr;lk++)
              {
                if(strcmp(temp3,symTab[lk])==0)
                {
                 llocptr=atoi(symadd[lk])+ atoi(temp4);
                }
              }
              itoa(llocptr,symadd[--t],10);
              locptr--;
              q=0;
              as=0;
              mn=0;
              kl=0;
            }
 elseif(strcmp(str[J],"AREG")==0 || strcmp(str[J],"BREG")==0 || strcmp(str[J],"CREG")==0 || strcmp(str[J],"DREG")==0 )
            {

             int ree=0,eee=0;
             char tee[10];
             kl=1;
             strcpy(tee,str[++J]);
             J--;
             if(strcmp(tee,"%")==0)
             {
                 J--;
                 for(int ll=0;ll<=3;ll++)
                 {
                 if(strcmp(str[J],reg[ll])==0)
                 {
                     eee=1;
                     J++;
                 }
                 }
             }

         else
             {
               kl=1;
               strcpy(tempe,str[--J]);
               for(int mis=0;mis<=10;mis++)
               {
                if(strcmp(tempe,is[mis])==0)
                   ree=1;
               }
             }
             if(ree==1)
             {
                 J++;
                 continue;
             }
             elseif(eee==0)
             {
                 err=5;
                 return;
             }
             else
             {
                 strcpy(tempe,str[++J]);
                 err=4;
                 return;
             }

            }
        }


        else
        {
          char er[10];
          kl=1;
          if(strcmp(str[J],"%")==0 )
          {
              locptr++;

            if(J!=2)
            {

              strcpy(temp,str[++J]);
              if(strcmp(temp,"PRINT")==0)
              {
                itoa(locptr,loccnt[loc],10);
                loc++;
                J++;
                locptr--;
              }


              elseif(strcmp(temp,"COMP")==0)
              {
                  itoa(locptr,loccnt[loc],10);
                  loc++;
                  J=J+2;
              }
              elseif(strcmp(temp,"LTORG")==0)
              {
                 lcntr=1;
                 itoa(locptr,loccnt[loc],10);
                 loc++;
                 for(int jk=0;jk<litatr;jk++)
                 {
                 if(strlen(litadd[jk])==0)
                 {
                   itoa(locptr,litadd[jk],10);
                   locptr++;
                 }
                 }
                 itoa(locptr,loccnt[loc],10);
                 loc++;
                 if(lcntr==1)
                 {
                 itoa(lcntr,poolTab[poolptr],10);
                 poolptr++;
                 }
                 else
                 {
                  itoa(litatr,poolTab[poolptr],10);
                  poolptr++;
                 }
                 locptr--;
              }


              elseif(strcmp(temp,"ORIGIN")==0)
              {
                int t3;
                mn=0,q=0,as=0;
                strcpy(temp3,"");
                strcpy(temp4,"");
                strcpy(temp2[0],str[++J]);
                strcpy(t2,temp2[0]);
                while(t2[q]!='+' && t2[q]!='-')
                {
                  temp3[mn]=t2[q];
                  q++;
                  mn++;
                }
                q++;
                temp3[mn]='\0';

                for(int h=0;h<symatr;h++)
                {
                  if(strcmp(temp3,symTab[h])==0)
                  {
                      t3=atoi(symadd[h]);
                  }
                }

                while(t2[q]!='\0')
                {
                 temp4[as]=t2[q];
                 q++;
                 as++;
                }
                temp4[as]='\0';
                locptr=t3+atoi(temp4)-1;
                 itoa(locptr,loccnt[loc],10);
                 loc++;
              }
              else
              {
                C=check(temp);
                if(C==1)
                {

                  itoa(locptr,loccnt[loc],10);
                  loc++;
                  cnt=0;
                }
                else
                {
                for( t=0;t<symatr;t++)
                {
                  if(strcmp(temp,symTab[t])==0)
                  {
                   char t1[5];
                   strcpy(er,str[++J]);
                   J--;
                   if(strcmp(er,"EQU")==0)
                   {
                       cntr=1;
                       continue;
                   }

               else
                   {
                   itoa(locptr,t1,10);
                   itoa(locptr,loccnt[loc],10);
                   loc++;
                   strcpy(symadd[t],t1);
                   cntr=1;
                   }
                  }
                }
                if(cntr==1)
                {
                  cntr=0;
                }
                else
                {
                   strcpy(symTab[symatr],str[J]);
                   itoa(locptr,symadd[symatr],10);
                    itoa(locptr,loccnt[loc],10);
                    loc++;
                   symatr++;
                }
                }
              }
            }
            else
            {
              C=check(str[++J]);
              if(C==0)
              {

                 strcpy(temp,str[J]);
                 strcpy(symTab[0],temp);
                 symatr++;
                 symptr=0;
                 char t1[10];
                 locptr--;
                 itoa(locptr,t1,10) ;
                  itoa(locptr,loccnt[0],10);
                  loc++;
                 strcpy(symadd[0],t1);
              }
            }
          }
          else
          {
            symptr=0;
            litptr=0;
            for (a=0;a<symatr;a++)
            {


               if(strcmp(symTab[a],str[J])==0)
                symptr=1;
            }
            for(int b=0;b<litatr;b++)
            {
               if(strcmp(litTab[b],str[J])==0)
                 litptr=1;
            }

                  if(symptr==1 || litptr==1)
                continue;
            else
            {
                int k=0,flag=0;
                strcpy(temp,str[J]);
                while(temp[k]!='\0')
                {
                if(temp[k]>='0' && temp[k]<='9')
                {
                    flag=1;
                    k++;
                    continue;
                }
                else
                    flag=0;
                k++;

                }

               if(flag==0)
               {
                  strcpy(symTab[symatr],str[J]);
                  strcpy(symadd[symatr],"");
                  symatr++;
                  symptr=0;
               }
               else
               {
                  strcpy(litTab[litatr],str[J]);
                  strcpy(litadd[litatr],"");
                  litatr++;
                  litptr=0;
               }
            }
            }
          }
        }
        }
        else
          err=2;
      }
    }
    else
    {
      err=1;
    }
}
int PassCode :: check(char *s)
{
        for( z=0;z<=10;z++)
        {
        if(strcmp(s,is[z])==0)
        {
            cnt=1;
            return 1;
        }
        else
            cnt=0;
        }
        for( x=1;x<=5;x++)
        {
         if(strcmp(s,ad[x])==0)
         {
            cnt=1;
            return 1;
         }
         else
            cnt=0;
        }
        for( c=1;c<=2;c++)
        {
         if(strcmp(s,dl[c])==0)
         {
            cnt=1;
            return 1;
         }
         else
            cnt=0;
        }
        for(r=0;r<=3;r++)
        {
         if(strcmp(s,reg[r])==0)
         {
             cnt=1;
             return 1  ;
         }
         else
             cnt=0;
        }
        for(cc=1;cc<=6;cc++)
        {
           if(strcmp(s,cd[cc])==0)
           {
             cnt=1;
             return 1;
           }
           else
            cnt=0;
        }
        return cnt;
}
void PassCode :: assum()
{
    clrscr();
    cout<<"\n\t IMPE STATS\t\t ASSEM DIRECTIVES\t\t DEC STATS";
    cout<<"\n\t ----------";
    cout<<"\t\t ----------------";
    cout<<"\t\t ---------";
    cout<<"\n\t|  00 STOP |\t\t|     01 START   |\t\t|  01 DC  |";
    cout<<"\n\t|  01 ADD  |\t\t|     02 END     |\t\t|  02 DS  |";
    cout<<"\n\t|  02 SUB  |\t\t|     03 ORIGIN  |\t\t|---------|";
    cout<<"\n\t|  03 MULT |\t\t|     04 EQU     |";
    cout<<"\n\t|  04 MOVER|\t\t|     05 LTORG   |";
    cout<<"\n\t|  05 MOVEM|\t\t|----------------|";
    cout<<"\n\t|  06 COMP |";
    cout<<"\n\t|  07 BC   |";
    cout<<"\n\t|  08 DIV  |";
    cout<<"\n\t|  09 READ |";
    cout<<"\n\t|  10 PRINT|";
    cout<<"\n\t|----------|";

    cout<<"\n\n\t REGISTERS\t\t CONDI STATS";
    cout<<"\n\t --------- \t\t -----------";
    cout<<"\n\t| 01 AREG |\t\t|   01 LT   |";
    cout<<"\n\t| 02 BREG |\t\t|   02 LE   |";
    cout<<"\n\t| 03 CREG |\t\t|   03 GT   |";
    cout<<"\n\t| 04 DREG |\t\t|   04 GE   |";
    cout<<"\n\t|---------|\t\t|   05 EQ   |";
    cout<<"\n\t           \t\t|   06 ANY  |";
    cout<<"\n\t           \t\t|-----------|";
    nosound();
}
void PassCode :: display()
{
   clrscr();
   if(err==5)
   {
      cout<<"\n\n\n\n\n\n\n\n\n\n    INVALID INPUT : ENTER ANY REGISTER ENTRY BEFORE SECOND REGISTER ENTRY ";
     return;
   }
   if(err==4)
   {
      cout<<"\n\n\n\n\n\n\n\n\n\n  INVALID INPUT : ENTER ANY IMPERATIVE STATEMENT BEFORE REGISTER ENTRY "<<tempe;
     return;
   }
   if(err==2)
   {
     cout<<"\n\n\n\n\n\n\n\n\n\n\t\tINVALID INPUT : ENTER CODE IN NEW LINE AFTER ADDRESS  "<<str[1];
     return;
   }
   if(err==3)
   {
    cout<<"\n\n\n\n\n\n\n\n\n\n\t\tINVALID INPUT : ENTER ADDRESS IN NUMERIC IN PLACE OF "<<str[1];
    return;
   }
   if(err==1)
   {
    cout<<endl<<"\n\n\n\n\n\n\n\n\n\n\t\t INVALID INPUT : PLEASE START CODING WITH KEYWORD START : ";
    return;
   }
   else
   {

    sound(976);
    cout<<"\n\n\t\t SYMTAB   SYMADD  "<<endl;
    cout<<"\t\t-----------------";
    for(int p=0;p<dil;p++)
    {

        if(strcmp(symTab[p],"%")==0)
           continue;
        else
        {
            cout<<endl<<"\t\t|   "<<symTab[p]<<"    |  "<<symadd[p]<<" |";

        }
    }


      cout<<"\n\t\t-----------------";
    if(litatr>0)
    {
      cout<<"\n\t\t LITTAB   LITADD  "<<endl;
      cout<<"\t\t-----------------";
      for(int u=0;u<litatr;u++)
      {
        cout<<endl<<"\t\t|   "<<litTab[u]<<"\t|  "<<litadd[u]<<"  |";
      }
        cout<<"\n\t\t-----------------";
      litatr++;
      itoa(litatr,poolTab[poolptr],10);
      cout<<"\n\t\t  POOLTAB ";
      cout<<"\n\t\t ----------";
      if(lcntr==0)
      {
         cout<<endl<<"\t\t |  # 1   |";
         cout<<"\n\t\t ----------";
         litatr--;
      }
      else
      {
         litatr--;
         for(int di=0;di<=poolptr;di++)
         {
        cout<<endl<<"\t\t |  # "<<poolTab[di]<<"   |";
        }
         cout<<"\n\t\t ----------";
      }
    }
    else
    {
      cout<<"\n\n\n\t\t THERE ARE NO ENTRY FOR LITRAL TABLE AND POOLTABLE :";
    }
   }
   nosound();
}
void PassCode :: displaycode()
{
   clrscr();
   int tru=0,fal=0,tr=0,ste=0,lte=0;
   char tempee[10];
   J=0,loc=0,tp=0,pt=0;
   tru=0,tr=0;
   if(err==5)
   {
      cout<<"\n\n\n\n\n\n\n\n\n\n    INVALID INPUT : ENTER ANY REGISTER ENTRY BEFORE SECOND REGISTER ENTRY ";
     return;
   }
   if(err==4)
   {
     cout<<"\n\n\n\n\n\n\n\n\n\n  INVALID INPUT : ENTER ANY IMPERATIVE STATEMENT BEFORE REGISTER ENTRY "<<tempe;
     return;
   }
   if(err==2)
   {
     cout<<"\n\n\n\n\n\n\n\n\n\n\t\tINVALID INPUT : PLEASE ENTER CODE IN NEW LINE AFTER ADDRESS  "<<str[1];
     return;
   }
   if(err==3)
   {
    cout<<"\n\n\n\n\n\n\n\n\n\n\t\tINVALID INPUT : ENTER ADDRESS IN NUMERIC IN PLACE OF "<<str[1];
    return;
   }

   if(err==1)
   {
      cout<<"\n\n\n\n\n\n\n\n\n\n\t\tINVALID INPUT : PLEASE START CODING WITH KEYWORD START :";
      return;
   }
   else
   {
      cout<<"\n\n\t ::::: INTERMEDIATE CODE FOR PASS-I AS FOLLOWS :::::";
      cout<<"\n\t ---------------------------------------------------";
      cout<<"\n\n\t\t[ (AD,01) (C,"<<str[1]<<") ]";
      for(J=2;J<I-1;J++)
      {
     fal=0;
     if(strcmp(str[J],"END")==0 )
     {

        getch();
        return;
     }
     else
     {

        if(strcmp(str[J],"%")==0)
        {
          strcpy(temp,str[++J]);
          for(i=0;i<symatr;i++)
          {


          if(temp[0]>='0' && temp[0]<='9')
          {
    
                cout<<"\n\n\t INVALID INPUT : THERE IS NUMBER AT LABEL PART :";
             return;
          }
          if(strcmp(temp,symTab[i])==0)
          {
             strcpy(tempee,str[++J]);
             J--;
             if(strcmp(tempee,"EQU")==0)
             {
                  fal=1;
                  continue;
             }
            else
            {
               cout<<"\n\t"<<loccnt[loc];
               loc++;
               fal=1;
            }
          }
          }
          
              if(fal==0)
          {
             for(z=0;z<=10;z++)
             {
              if(strcmp(temp,is[z])==0)
              {
                 if(z==10)
                 {
                     cout<<"\n\t"<<loccnt[loc];
                         loc++;
                     cout<<"     (IS,"<<z<<")";
                 }
                 else
                 {
                      cout<<"\n\t"<<loccnt[loc];
                        loc++;
                        cout<<"     (IS,0"<<z<<")";
                  }
                 tru=1;
              }
             }

             for(x=1;x<=5;x++)
             {
              if(strcmp(temp,ad[x])==0)
              {
                 if(strcmp(temp,"ORIGIN")==0)
                 {
                  loc++;
                  J++;
                  tru=1;
                  continue;
                 }
                 else
                 {
                     cout<<"\n\t"<<loccnt[loc];
                     loc++;
                     cout<<"     (AD,0"<<x<<")";
                     tru=1;
                 }
              }
             }
             if(tru==1)
                continue;
             else
             {
              cout<<"\n\n\t INVALID INPUT :";
              return;
             }

          }

        }
        
         else
        {
          for(z=0;z<=10;z++)
          {
          if(strcmp(str[J],is[z])==0)
          {
             if(z==10)
              {
              cout<<"     (IS,"<<z<<")";
              }
             else
              cout<<"     (IS,0"<<z<<")";
             tr=1;
          }
          }
          for(x=1;x<=5;x++)
          {
          if(strcmp(str[J],ad[x])==0)
          {
             if(strcmp(str[J],"EQU")==0)
             {
              for(int up=0;up<symatr;up++)
              {
                 if(strcmp(temp5,symTab[up])==0)
                 {
                  cout<<"\n\t\t[ (AD,0"<<x<<") (S,#"<<++up<<")                             "<<temp9[tp]<<" "<<temp10[pt]<<" ]";
                  tp++;
                  pt++;
                  tr=1;
                  J++;
                 }
              }
             }
             elseif(strcmp(str[J],"ORIGIN")==0)
             {
                  tr=1;
             }
             else
             {
              cout<<"     (AD,0"<<x<<")";
              tr=1;
             }
          }
          }
          for(c=1;c<=2;c++)
          {
          if(strcmp(str[J],dl[c])==0)
          {
             for(int pu=0;pu<symatr;pu++)
             {
             if(strcmp(temp,symTab[pu])==0)
             {
                cout<<"     (DL,0"<<c<<") (C,"<<str[++J]<<")";
                tr=1;
             }
             }

          }
          }
          


              for(r=0;r<=3;r++)
          {
          if(strcmp(str[J],reg[r])==0)
          {
             cout<<" ("<<++r<<")";
             tr=1;
          }
          }
          for(cc=1;cc<=6;cc++)
          {
          if(strcmp(str[J],cd[cc])==0)
          {
             cout<<" ("<<cc<<")";
             tr=1;
          }
          }
          for(ste=0;ste<symatr;ste++)
          {
          if(strcmp(str[J],symTab[ste])==0)
          {
             cout<<" (S,#"<<ste+1<<")";
             tr=1;
          }
          }
          for(lte=0;lte<litatr;lte++)
          {
          if(strcmp(str[J],litTab[lte])==0)
          {
             cout<<" (L,#"<<lte+1<<")";
             tr=1;
          }
          }
          if(tr==1)
           continue;
          else
          {
           cout<<"\n\n\n INVALID INPUT : ";
           return;
          }
        }
      }
     }
   }

   nosound();
}


void PassCode :: dispass2()
{
    clrscr();
    int gh=0,hdf=0,ste=0,lte=0,al=0,usa=0;
    char tempo[10];
    gh=atoi(str[1]);
    if(err==5)
    {
      cout<<"\n\n\n\n\n\n\n\n\n\n    INVALID INPUT : ENTER ANY REGISTER ENTRY BEFORE SECOND REGISTER ENTRY ";
     return;
    }

    if(err==4)
    {
     cout<<"\n\n\n\n\n\n\n\n\n\n  INVALID INPUT : ENTER ANY IMPERATIVE STATEMENT BEFORE REGISTER ENTRY "<<tempe;
     return;
    }
    if(err==2)
    {
     cout<<"\n\n\n\n\n\n\n\n\n\n\t\tINVALID INPUT : PLEASE ENTER CODE IN NEW LINE AFTER ADDRESS  "<<str[1];
     return;
    }
    if(err==3)
    {
    cout<<"\n\n\n\n\n\n\n\n\n\n\t\tINVALID INPUT : ENTER ADDRESS IN NUMERIC IN PLACE OF "<<str[1];
    return;
    }

    if(err==1)
    {
      cout<<"\n\n\n\n\n\n\n\n\n\n\t\tINVALID INPUT : PLEASE START CODING WITH KEYWORD START :";
      return;
    }
    else
    {
    cout<<"\n\n\t ::::: INTERMEDIATE CODE FOR PASS-II AS FOLLOWS :::::";
    cout<<"\n\t -----------------------------------------------"<<endl<<endl;
    for(J=2;J<I-1;J++)
      {
       hdf=0,al=0,usa=0;
       if(strcmp(str[J],"%")==0)
       {
    strcpy(temp,str[++J]);
    for(ste=0;ste<symatr;ste++)
    {
        if(strcmp(temp,symTab[ste])==0)
        {
         strcpy(tempo,str[++J]);
         J--;
         if(strcmp(tempo,"EQU")==0)
         {
              J=J+2;
              al=1;
              usa=1;
         }
         else
         {
            cout<<"\n\t\t"<<gh;
            gh++;
            J++;
            al=1;
            strcpy(temp,str[J]);
         }
        }
    }
    
     for(z=0;z<=10;z++)
    {
      if(strcmp(temp,is[z])==0)
      {
         if(al==0)
         {
        cout<<"\n\t\t"<<gh;
        gh++;
         }
         if(z==10)
         {
           cout<<"     "<<z;
         }
         else
         {
        cout<<"     0"<<z;
         }
         J++;
      }
    }
    for(x=1;x<=5;x++)
    {

      if(strcmp(temp,ad[x])==0)
      {
         if(strcmp(temp,"LTORG")==0)
         {

         for(int ty=0;ty<litatr;ty++)
         {
            cout<<"\n\t\t"<<gh;
            cout<<"     00   (0)   0"<<litTab[ty];
            gh++;
         }
         hdf=1;
         }

         elseif(strcmp(temp,"EQU")==0)
         {
          J++;
          continue;
         }
         elseif(strcmp(temp,"ORIGIN")==0)
         {
         J++;
         continue;
         }
         elseif(strcmp(temp,"END")==0)
         {
           cout<<"\n\t\t"<<gh;
           gh++;
        cout<<"     00   (0)   000";
        return;
         }
      }
    }

      for(r=0;r<=3;r++)
    {
      if(strcmp(str[J],reg[r])==0)
      {
         cout<<"   ("<<++r<<")";
         J++;
         hdf=1;
      }
    }
    for(cc=1;cc<=6;cc++)
    {
      if(strcmp(str[J],cd[cc])==0)
      {
        cout<<"   ("<<cc<<")";
        J++;
        hdf=1;
      }
    }
    if(usa==1)
    {
        continue;
    }
    else
    {
       if(hdf==1)
       {
        hdf=0;
       }
       else
       {
         cout<<"   (0)";
         J++;
       }
    }
    for(ste=0;ste<symatr;ste++)
    {
      if(strcmp(str[J],symTab[ste])==0)
      {
         cout<<"   "<<symadd[ste];
      }
    }
    for(lte=0;lte<litatr;lte++)
    {
      if(strcmp(str[J],litTab[lte])==0)
      {
         cout<<"   "<<litadd[lte];
      }
    }
       }
      }
    }
    nosound();
}
void main()
{
    clrscr();
    int choice;
    PassCode P;
    P.getCode();
    P.disCode();
    while(1)
    {
           clrscr();
           cout<<"\n\n\n\n\n\t\t\t 1. FOR ASSEMBLY CODE DISPLAY";
           cout<<"\n\t\t\t 2. FOR ASSUMPTION DISPLAY";
           cout<<"\n\t\t\t 3. FOR TABLES DISPLAY";
           cout<<"\n\t\t\t 4. FOR INTERMEDIATE CODE DISPLAY FOR PASS-I";
           cout<<"\n\t\t\t 5. FOR INTREMEDIATE CODE DISPLAY FOR PASS-II";
           cout<<"\n\t\t\t 0. FOR EXIT";
           cout<<"\n\n\t\t\t    ENTER YOUR CHOICE :-----> ";
           nosound();
           cin>>choice;
           switch(choice)
           {
           case 1:
                 P.asscode();
                 getch();
                 break;
           case 2:
                 P.assum();
                 getch();
                 break;
           case 3:
                 P.display();
                 getch();
                 break;
           case 4:
                 P.displaycode();
                 getch();
                 break;
           case 5:
                 P.dispass2();
                 getch();
                 break;
           case 0:
                 exit(0);
           default:
                 cout<<"\n\n\t\t\t  WRONG ENTRY !!!!";
                 getch();
                 break;
           }
    }
}


 OUTPUT
************
                                    1.  FOR ASSEMBLY CODE DISPLAY
                                    2.  FOR ASSUMPTION DISPLAY
                                    3.  FOR TABLES DISPLAY
                                    4.  FOR INTERMEDIATE CODE DISPLAY FOR PASS-I
                                    5.  FOR INTREMEDIATE CODE DISPLAY FOR PASS-II
                                    0.  FOR EXIT
       
 ENTER YOUR CHOICE :----->1

                                    START 101
                                X   ADD AREG,10
                                    SUB BREG,Y
                                    MULT CREG,20
                                    ADD BREG,X
                                Y   EQU X+1
                                    LTORG
                                    END


                                    1. FOR ASSEMBLY CODE DISPLAY
                                    2. FOR ASSUMPTION DISPLAY
                                    3. FOR TABLES DISPLAY
                                    4. FOR INTERMEDIATE CODE DISPLAY FOR PASS-I
                                    5. FOR INTREMEDIATE CODE DISPLAY FOR PASS-II
                                    0. FOR EXIT

ENTER YOUR CHOICE :-----> 2

                                    IMPE STATS              ASSEM DIRECTIVES                DEC STATS
                                    ----------                  ----------------                        ---------
                                   |  00 STOP |              |     01 START   |                   |  01 DC  |
                                   |  01 ADD  |              |     02 END     |                      |  02 DS  |
                                   |  02 SUB  |               |     03 ORIGIN  |                   |---------|
                                   |  03 MULT |            |     04 EQU     |
                                   |  04 MOVER|          |     05 LTORG   |
                                   |  05 MOVEM|         |----------------|
                                   |  06 COMP |
                                   |  07 BC   |
                                   |  08 DIV  |
                                   |  09 READ |
                                   |  10 PRINT|
                                   |----------|

                                   REGISTERS               CONDI STATS
                                   ---------                   -----------
                                  | 01 AREG |                 |   01 LT   |
                                  | 02 BREG |                 |   02 LE   |
                                  | 03 CREG |                 |   03 GT   |
                                  | 04 DREG |                 |   04 GE   |
                                  |---------|                      |   05 EQ   |
                                                                        |   06 ANY  |
                                                         |-----------|

                                  1. FOR ASSEMBLY CODE DISPLAY
                                  2. FOR ASSUMPTION DISPLAY
                                  3. FOR TABLES DISPLAY
                                  4. FOR INTERMEDIATE CODE DISPLAY FOR PASS-I
                                  5. FOR INTREMEDIATE CODE DISPLAY FOR PASS-II
                                  0. FOR EXIT

ENTER YOUR CHOICE :-----> 3

                                  SYMTAB   SYMADD
                                  -----------------
                                  |   X    |  101 |
                                  |   Y    |  102 |
                                  -----------------
                                  LITTAB   LITADD
                                  -----------------
                                  |   10  |  105  |
                                  |   20  |  106  |
                                  -----------------
                                  POOLTAB
                                  ----------
                                  |  # 1   |
                                  |  # 3   |
                                  ----------

                                  1. FOR ASSEMBLY CODE DISPLAY
                                  2. FOR ASSUMPTION DISPLAY
                                  3. FOR TABLES DISPLAY
                                  4. FOR INTERMEDIATE CODE DISPLAY FOR PASS-I
                                  5. FOR INTREMEDIATE CODE DISPLAY FOR PASS-II
                                  0. FOR EXIT

ENTER YOUR CHOICE :-----> 4

                                  ::::: INTERMEDIATE CODE FOR PASS-I AS FOLLOWS 
                                  ---------------------------------------------------

                                          [ (AD,01) (C,101) ]
                                  101     (IS,01) (1) (L,#1)
                                  102     (IS,02) (2) (S,#2)
                                  103     (IS,03) (3) (L,#2)
                                  104     (IS,01) (2) (S,#1)
                                          [ (AD,04) (S,#1) + 1 ]
                                  105     (AD,05)
                                  107     (AD,02)

                                 1. FOR ASSEMBLY CODE DISPLAY
                                  2. FOR ASSUMPTION DISPLAY
                                  3. FOR TABLES DISPLAY
                                  4. FOR INTERMEDIATE CODE DISPLAY FOR PASS-I
                                  5. FOR INTREMEDIATE CODE DISPLAY FOR PASS-II
                                  0. FOR EXIT

ENTER YOUR CHOICE :-----> 5

                                 ::::: INTERMEDIATE CODE FOR PASS-II AS FOLLOWS 
                                  -----------------------------------------------
                                  101     01   (1)   105
                                  102     02   (2)   102
                                  103     03   (3)   106
                                  104     01   (2)   101
                                  105     00   (0)   010
                                  106     00   (0)   020
                                  107     00   (0)   000

                                  1. FOR ASSEMBLY CODE DISPLAY
                                  2. FOR ASSUMPTION DISPLAY
                                  3. FOR TABLES DISPLAY
                                  4. FOR INTERMEDIATE CODE DISPLAY FOR PASS-I
                                  5. FOR INTREMEDIATE CODE DISPLAY FOR PASS-II
                                  0. FOR EXIT

                                  ENTER YOUR CHOICE :-----> 0
  
Share: 

 
 

Didn't find what you were looking for? Find more on PROGRAM FOR PASS-I & PASS-II Or get search suggestion and latest updates.

Isaac Evans
Isaac Evans author of PROGRAM FOR PASS-I & PASS-II is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!