C program for Pass-1 Assembler

Monday, March 29th, 2010

C program for Pass-1 Assembler

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int symi=0,lc=0,len=1,dc=0,start=0;
struct pgm
 {
   char line[80];
 } s[100];
struct symtab
 {
   char name[10];
   int add;
 } sym[100];
void show(char* a,char* b,char* c)
 {
   printf("%8s %5s %6s \n",a,b,c);
 }
void check(char s[])
 {
   if(!strcmpi(s,"START"))
   {
     start=1;
     show("","START","1");
     return;
   }
   if(!strcmpi(s,"END"))
    {
      show("","END","1");
      return;
    }
    if(!strcmpi(s,"EQU"))
     {
       show("","EQU","1");
       return;
    }
   if(!strcmpi(s,"DS"))
    {
      show("","DS","1");
      return;
    }
  if(!strcmpi(s,"ORG"))
   {
   show("","ORG","1");
   return;
 }
if(!strcmpi(s,"DC"))
 {
   show("","DC","1");
   return;
 }
if(start)
 {
   start=0;
   lc=atoi(s);
   return;
 }
if(dc)
 {
   dc=0;
   len=atoi(s);
   show("","DS",s);
   return;
 }
for(int i=0;i<symi;i++)
 {
    if(strcmp(sym[i].name,s)==0)
    return;
 }
if(s[0]=='\'')
 {
   char p[2];
   sprintf(p,"LIT : %s",s);
   show(p,"-","-");
   return;
 }
strcpy(sym[symi++].name,s);
show(s,"-","-");
return;
}
void main()
 {
   char t[20];
   int i=0,j=0,k=0;
   cout<<"Enter the Program code:";
   do
    {
     gets(s[i].line);
    }
   while(strcmpi(s[i++].line,"end"));
   printf("Systab Optab Length \n");
   printf("---------------------");
   k=-1;
   do
     {
       k++;
       for(i=0;s[k].line[i]!='\o';i++,j++)
      {
        if(s[k].line[i]==' ')
        {
          t[j]='\o';
          j=-1;
          check(t);
        }
       else
         t[j] = s[k].line[i];
     }
       t[j]='\o';
       j=0;
      check(t);
  }
while(strcmpi(s[k].line,"End"));
getch();
}
Avatar Image

Author Name :
Ranjith

Total : 15 Comments


15 Responses to “C program for Pass-1 Assembler”

  1. DHANRAJ says:

    NICE

  2. niks says:

    we want this prog. in only c…………

    you use c++ function so it give error………..

  3. mdmohsin says:

    the programe for pass1&pass2 with symboltable&literaltable & other

  4. avinash says:

    Thank you …it will help me….

  5. komal says:

    Thank you

  6. abhishek says:

    magg>>>>>>>>>>>>>>>>>>>>>>>’

  7. shobana says:

    nice ..thank you…

  8. kumar k s says:

    thank u……….

  9. hessar says:

    hi
    please change program source data to file, that this can open file for convert

  10. Parth says:

    Its good… Thanks :)

  11. md imran says:

    thanks

  12. dipti says:

    thank you :D

  13. Matheen says:

    Hello Ranjith !
    I have tried your c program.
    But i dono how to give input.
    Could you please tell how to we give input to that program?

  14. selvamani says:

    hai thank you ma

  15. anshika says:

    error occurs due to #incude and cout<<..why to use c++?

Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup