473,473 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Program working in Dev C++ but fails in Turbo C

1 New Member
A Sic 2 pass assembler which is coded using Dev c++ gets stuck in Turbo C...guys plz help


Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. #include<string.h>
  5. #include<math.h>
  6. #include<stdlib.h>
  7.  
  8.  
  9. struct stmt
  10. {
  11.        char add[32];
  12.        char lab[32];
  13.        char opc[32];
  14.        char opr[32];
  15. };
  16.  
  17.  
  18. struct optab
  19. {
  20.        char opc[32];
  21.        int val;
  22. };
  23.  
  24. struct symtab
  25. {
  26.        char sym[32];
  27.        int  loc;
  28. };
  29.  
  30.  
  31. long locctr=0,strt_addr=0,len=0;
  32.  
  33.  
  34. int search_symtab(char *a)                        //function to search symtab......
  35. {
  36.     FILE *fsym;
  37.     char b[32];
  38.     strcpy(b,a);
  39.  
  40.     int i;
  41.     for(i=0;a[i]!=','&&a[i]!='\0';i++);
  42.     a[i]='\0';
  43.  
  44.     fsym=fopen("symtab.txt","r");
  45.     symtab symb;
  46.     while(!feof(fsym))
  47.     {
  48.                       fscanf(fsym,"%s\t%x",symb.sym,&symb.loc);
  49.                       if(strcmp(symb.sym,a)==0)
  50.                       { 
  51.                        strcpy(a,b);
  52.                        return symb.loc;
  53.                       }
  54.  
  55.     }
  56.     strcpy(a,b);
  57.     return -1;
  58. }                      
  59.  
  60.  
  61. int search_optab(char a[100])                    //function to search optab....
  62. {
  63.     FILE *fsym;
  64.     fsym=fopen("optab.txt","r");
  65.     optab op;
  66.     while(!feof(fsym))
  67.     {
  68.                       fscanf(fsym,"%s\t%x",op.opc,&op.val);
  69.                       if(strcmp(op.opc,a)==0)
  70.                        return op.val;
  71.  
  72.     }
  73.  
  74.     return -1;
  75.  
  76.  
  77. long hextoint(char *a)           //converting hex to integer
  78. {
  79.  
  80.     int len=strlen(a);
  81.     long temp=0,t;
  82.     for(int i=len-1,j=0;i>=0;i--,j++)
  83.     {
  84.             if((int)a[i]>=48&&(int)a[i]<=56)
  85.             t=(int)a[i]-48;
  86.             else
  87.             t=(int)a[i]-53;
  88.  
  89.             temp=temp+t*(pow(16,j));  
  90.     }         
  91.  
  92.     return temp;
  93. }
  94.  
  95.  
  96. void add_sym(char *a,int loc,FILE *fous)       //function to add symbol to symtab............
  97. {
  98.      fprintf(fous,"%s\t%05X\n",a,loc);
  99. }
  100.  
  101.  
  102. stmt read_stmt(FILE *fins,int p)                 //function to read single line from source file.....
  103. {
  104.     stmt tem;
  105.     char s[100],t[4][40];
  106.     int i,j,k,l,fl=0;
  107.  
  108.     fgets(s,100,fins);
  109.  
  110.     k=0;
  111.     for(i=0;i<2+p;i++)
  112.     {
  113.       l=0;
  114.       for(j=k;s[j]!='\t'&&s[j]!='\n';j++)
  115.       {       
  116.            if(s[j]=='.')
  117.            {
  118.                         fl=1;
  119.                         break;
  120.            }
  121.            else                                 
  122.            {
  123.                         t[i][l]=s[j];
  124.                         l++;
  125.            }
  126.  
  127.       }
  128.  
  129.       if(fl==1)
  130.       break;
  131.  
  132.       t[i][l]='\0';
  133.       k=j+1;
  134.  
  135.  
  136.     }
  137.  
  138.     if(fl==1)
  139.     {
  140.                 tem.lab[0]='.';
  141.     }
  142.     else if(p==1)        
  143.     {
  144.                 strcpy(tem.lab,t[0]);
  145.                 strcpy(tem.opc,t[1]);
  146.                 strcpy(tem.opr,t[2]);  
  147.     }
  148.     else
  149.     {
  150.                 strcpy(tem.add,t[0]);
  151.                 strcpy(tem.lab,t[1]);
  152.                 strcpy(tem.opc,t[2]);
  153.                 strcpy(tem.opr,t[3]);
  154.     }
  155.  
  156.  
  157.  
  158.     return tem;
  159. }  
  160.  
  161.  
  162. void inslen(int d)
  163. {
  164.      char c,s[100];
  165.      FILE *fon;
  166.      fon=fopen("obj.txt","r+");
  167.  
  168.  
  169.      int fl=0;
  170.  
  171.      while(!feof(fon))
  172.      {
  173.  
  174.                       c=fgetc(fon);
  175.  
  176.                       if(c=='T')
  177.                        fl=1;
  178.  
  179.                       if((c==' ')&&(fl==1))
  180.                       {
  181.  
  182.                               fseek(fon,-1,SEEK_CUR);
  183.                               fprintf(fon,"%02X",d);
  184.                               break;
  185.                       }
  186.  
  187.      }
  188.  
  189.      fclose(fon);
  190.  
  191. }     
  192.  
  193.  
  194. int getlen( char *a)
  195. {
  196.     int k;
  197.     for(k=2;a[k]!='\'';k++);
  198.     if(a[0]=='C')                    
  199.       return k-2;
  200.     else
  201.       return (k-2)/2; 
  202. }
  203.  
  204.  
  205. void pass1()
  206. {
  207.      FILE *fino,*foui,*fous,*fins;
  208.      fins=fopen("source.txt","r");
  209.      foui=fopen("inter.txt","w");
  210.      fino=fopen("optab.txt","r");
  211.      fous=fopen("symtab.txt","w");
  212.  
  213.      stmt temp;
  214.      temp=read_stmt(fins,1);
  215.  
  216.      long lineno=1,ln=0,k;
  217.  
  218.      locctr=hextoint(temp.opr);
  219.  
  220.  
  221.      if(strlen(temp.lab)==0)
  222.       cout<<"Program name not defined!!\n";
  223.      else
  224.       add_sym(temp.lab,locctr,fous);
  225.      if(strlen(temp.opr)>0)
  226.       {
  227.  
  228.                   strt_addr=locctr;
  229.                   fprintf(foui,"%05X\t%s\t%s\t%s\n",locctr,temp.lab,temp.opc,temp.opr);
  230.       }
  231.      else
  232.      {
  233.          locctr=0;
  234.          strt_addr=locctr;
  235.      }
  236.  
  237.      temp=read_stmt(fins,1);
  238.  
  239.      while(strcmp(temp.opc,"END")!=0&&!feof(fins))
  240.      {
  241.  
  242.                  ln=locctr;
  243.                  if(temp.lab[0]!='.')             //if not a comment line
  244.                  {
  245.                         if(strlen(temp.lab)!=0)
  246.                         {
  247.                                 if(search_symtab(temp.lab)!=-1)
  248.                                 {
  249.                                           cout<<"Error at line : "<<lineno<<"\n";
  250.                                           getch();
  251.                                 }
  252.                                 else
  253.                                 {
  254.                                              add_sym(temp.lab,locctr,fous);
  255.  
  256.                                 }
  257.                         } 
  258.                         if(search_optab(temp.opc)!=-1)
  259.                         {
  260.  
  261.                                 locctr=locctr+3;
  262.                         }
  263.                         else if(strcmp(temp.opc,"WORD")==0)
  264.                         {
  265.                                 locctr=locctr+3;
  266.                         }
  267.                         else if(strcmp(temp.opc,"RESW")==0)
  268.                         {
  269.                                 locctr=locctr+3*atoi(temp.opr);
  270.                         }
  271.                         else if(strcmp(temp.opc,"RESB")==0)
  272.                         {
  273.                                 locctr=locctr+atoi(temp.opr);
  274.                         }
  275.                         else if(strcmp(temp.opc,"BYTE")==0)
  276.                         {
  277.                                  k=getlen(temp.opr);
  278.                                  locctr=locctr+k;    
  279.                         }
  280.                         else
  281.                          cout<<"Error at line : "<<lineno<<"\n";
  282.                  }
  283.                  lineno++;
  284.                  if(temp.lab[0]!='.')
  285.                  {
  286.  
  287.                                      fprintf(foui,"%05X\t%s\t%s\t%s\n",ln,temp.lab,temp.opc,temp.opr);
  288.                  }
  289.  
  290.  
  291.                  temp=read_stmt(fins,1);
  292.      }    
  293.  
  294.       fprintf(foui,"\t%s\t%s\t%s\n",temp.lab,temp.opc,temp.opr);                                  
  295.       len=locctr-strt_addr;                                                       
  296.  
  297.       fclose(fino);
  298.       fclose(foui);
  299.       fclose(fins);
  300.       fclose(fous);                                       
  301.  
  302. }
  303.  
  304.  
  305. void pass2()
  306. {
  307.      FILE *fini,*fouo;
  308.      char buff[100];
  309.      int lim=0,lim1=0,op,sm,st;
  310.      st=strt_addr;
  311.  
  312.      long ob,i=0;
  313.      fini=fopen("inter.txt","r");
  314.      fouo=fopen("obj.txt","w");
  315.      stmt temp=read_stmt(fini,2);
  316.  
  317.      if(strcmp(temp.opc,"START")==0)
  318.         fprintf(fouo,"%c^%-6s^%06X^%06X\n",'H',temp.lab,strt_addr,len);
  319.      temp=read_stmt(fini,2);
  320.      fprintf(fouo,"%c^%06X^  ",'T',st);
  321.  
  322.      while(strcmp(temp.opc,"END")!=0&&!feof(fini))
  323.      {
  324.  
  325.               op=search_optab(temp.opc);
  326.               if(op!=-1)
  327.               {
  328.  
  329.                         if(strlen(temp.opr)>1)
  330.                         {
  331.  
  332.                               sm=search_symtab(temp.opr);
  333.                               if(sm==-1)
  334.                               {   
  335.                                   cout<<"Symbol "<<temp.opr<<" not defined!!";
  336.                                   sm=0;
  337.                               }
  338.                         }
  339.                         else
  340.                              sm=0;
  341.  
  342.                         int stl;
  343.                         stl=strlen(temp.opr);
  344.  
  345.                         if(temp.opr[stl-1]!='X')
  346.                             ob=sm;
  347.                         else
  348.                         {
  349.                             ob=sm+32768;
  350.                         }
  351.  
  352.  
  353.                         if((lim+3)>30)
  354.                         {
  355.                             fflush(fouo);
  356.                             inslen(lim1);
  357.                             st=st+lim;
  358.                             lim1=0;
  359.                             lim=0;
  360.                             fprintf(fouo,"\n%c^%06X^  ",'T',st);
  361.  
  362.                         }
  363.  
  364.                         fprintf(fouo,"^%02X%04X",op,(int)ob);
  365.                         lim=lim+3;
  366.                         lim1=lim1+3;
  367.  
  368.               }
  369.  
  370.               else if(strcmp(temp.opc,"BYTE")==0)
  371.               {
  372.  
  373.                    int l=getlen(temp.opr);
  374.  
  375.                   if(temp.opr[0]=='C')
  376.                   {
  377.  
  378.                       if((lim+l)>30)
  379.                         {
  380.                             fflush(fouo);
  381.                             inslen(lim1);
  382.                             st=st+lim;
  383.                             lim1=0;
  384.                             lim=0;
  385.                             fprintf(fouo,"\n%c^%06X^  ",'T',st);
  386.                         }
  387.                       fprintf(fouo,"^"); 
  388.                       for(int k=2;temp.opr[k]!='\'';k++)
  389.                       {
  390.                               fprintf(fouo,"%X",(int)temp.opr[k]);
  391.  
  392.                       }
  393.  
  394.                   }
  395.                   else if(temp.opr[0]=='X')
  396.                   {
  397.                        int k;
  398.                       char s[32];
  399.  
  400.                       if((lim+l)>30)
  401.                         {
  402.                             fflush(fouo);
  403.                             inslen(lim1);
  404.                             st=st+lim;
  405.                             lim1=0;
  406.                             lim=0;
  407.                             fprintf(fouo,"\n%c^%06X^  ",'T',st);
  408.                         }
  409.  
  410.                       for(k=2;temp.opr[k]!='\'';k++)
  411.                        s[k-2]=temp.opr[k];
  412.                       s[k-2]='\0';
  413.                       fprintf(fouo,"^%s",s);
  414.                   }
  415.  
  416.                   lim=lim+l;
  417.                   lim1=lim1+l;
  418.               }
  419.               else if(strcmp(temp.opc,"WORD")==0)
  420.               {
  421.                    if((lim+3)>30)
  422.                         {
  423.                             fflush(fouo);
  424.                             inslen(lim1);
  425.                             st=st+lim;
  426.                             lim1=0;
  427.                             lim=0;
  428.  
  429.                             fprintf(fouo,"\n%c^%06X^  ",'T',st);
  430.  
  431.                         }
  432.  
  433.                         fprintf(fouo,"^%06X",atoi(temp.opr));
  434.                         lim=lim+3;
  435.                         lim1=lim1+3;
  436.               }
  437.  
  438.  
  439.               else if(strcmp(temp.opc,"RESB")==0)
  440.               {
  441.  
  442.                        int ak=atoi(temp.opr);
  443.  
  444.                        lim=lim+ak;
  445.  
  446.  
  447.               }
  448.  
  449.               else if(strcmp(temp.opc,"RESW")==0)
  450.               {
  451.  
  452.                        int ak=atoi(temp.opr);
  453.                        lim=lim+3*ak;
  454.  
  455.               }
  456.  
  457.               temp=read_stmt(fini,2);
  458.  
  459.      }
  460.      fflush(fouo);
  461.      inslen(lim1);
  462.      fprintf(fouo,"\n%c^%06X",'E',strt_addr);
  463.  
  464.      fclose(fouo);
  465.      fclose(fini);
  466.  
  467. }
  468.  
  469.  
  470. int main()
  471. {
  472.  
  473.     pass1();
  474.     cout<<"Pass 1 completed.....intermediate file created!!\n";
  475.     pass2();
  476.     cout<<"Pass 2 completed.....object file created!!\n";
  477.     getch();
  478.     return 0;
  479.  
  480. }
  481.  
Jan 4 '12 #1
1 2433
weaknessforcats
9,208 Recognized Expert Moderator Expert
What do you mean by "getting stuck"?

a) the compiler hangs?
b) the executable hangs?
c) there is a compiler error produced?
d) the linker fails?
etc...

I can't debug 481 lines of code for you.
Jan 4 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: MariusI | last post by:
I've created a program which fetches data from the internet using the WebBrowser and HttpWebRequest classes. The program has been tested on several computers and everything was working fine until...
1
by: srinpraveen | last post by:
I want to put a jpeg or gif or bitmap image onto my C++ program. I am working in Turbo C++ environment. How do I implement it? I found that putimage() attribute does not satisfy my need. I am just...
3
by: srinpraveen | last post by:
I want to put a bitmap image which I have created using Microsoft paint onto my C++ program. I am working in Turbo C++ environment. How do I implement it? I found that putimage() attribute does not...
1
by: LKavitha4 | last post by:
hi, Does writing c++ program in windows turbo c is similar to red hat linux. My c++ program is runnning correct in turbo c but the same program is not working in red hat linux. Also say how to...
2
by: jocobunshin | last post by:
Hi there! I'm new in Turbo C... uhmm our teacher gave us a project to make a program in Turbo C. Im from the Philippines, and our project is due on tuesday, februrary 13, 2007... can anyone check my...
1
by: Ş­¾¯ | last post by:
/************************************************** *** *** chrexec.c *** *This shit can be called from root or from any user (in that case executable * should have 06755 permisions) and should...
2
by: manjuscripts | last post by:
Which compliler is best for C Program ,GCC or Turbo C/C++ compiler?
0
by: sagreen | last post by:
Hi all, I am reviewing an old application for my client. This application is some kind of a computerized catalog and the there is one big .CDB file (around 450Mb) whiche contain all the data. I...
10
by: lvl 1 monk | last post by:
Hi all, I don't really have the money for the formal route so I went to the library and picked up an older c++ book and it seems I run into "antiquated headers" over and over again. The problem...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.