• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

ProjectsGeek

Lexical analyzer Code in C Language

May 4, 2011 by ProjectsGeek Leave a Comment

Lexical analyzer Code in C Language

Implement Lexical Analyzer code for subset of C using C Language.

Lexical Analysis-Finite Automate, Regular Expression, RE to DFA,Implementation of lexical Analyzer,Syntax Analysis,Context Free Grammars ,Derivation of Parse Tress,Parsers,Top Down Parsers: Recursive Descent Parser, Predictive Parser,Bottom Up Parsing Shift Reduce Parser, SLR parser and Lexical analyzer Code.

 Lexical analyzer Code

#include  
 #include  
 #include  
 #include  
 #define max 100  
 typedef struct lit_tab  
 {  
   char token[max];  
 }littab;  
 typedef struct iden_tab  
 {  
   char token[max];  
 }identab;  
 typedef struct ust  
 {  
   char token[max];  
   char type;  
   int pos;  
 }ustx;  
 littab lit_tab[50];  
 identab iden_tab[50];  
 ustx ust[100];  
 int ust_ptr=0;  
 char terminal[max][max]={"{","}","(",")","<",">","<=",">=","=",",",";","\"","+","-","*","/","void","printf","int","float","if","else"};  
 void print_ust()  
 {  
   printf("UST\n");  
   int i=0;  
   printf("TOKEN\tTYPE\tPOS\n");  
   while(i<ust_ptr) <br="">   {  
     printf("%s\t%c\t%d\n",ust[i].token,ust[i].type,ust[i].pos);  
     i++;  
     getch();  
   }  
 }  
 void print_ter()  
 {  
   printf("Literal Table");  
   int i=0;  
   clrscr();  
   while(strcmp(terminal[i],NULL)!=0)  
   {  
     printf("%d.%s\n",i+1,terminal[i]);  
     i++;  
   }  
   getch();  
 }  
 void print_lit()  
 {  
   printf("\nLiteral Table");  
   int i=0;  
   clrscr();  
   while(strcmp(lit_tab[i].token,NULL)!=0)  
   {  
     printf("%d.%s\n",i+1,lit_tab[i].token);  
     i++;  
   }  
   getch();  
 }  
 void print_iden()  
 {  
   printf("\nIdentifier Table");  
   int i=0;  
   clrscr();  
   while(strcmp(iden_tab[i].token,NULL)!=0)  
   {  
     printf("%d.%s\n",i+1,iden_tab[i].token);  
     i++;  
   }  
   getch();  
 }  
 int search_lit(char str[])  
 {  
   int i=0;  
    while(strcmp(lit_tab[i].token,NULL)!=0)  
    {  
     if(strcmp(lit_tab[i].token,str)==0)  
       return i;  
     i++;  
    }  
    return -1;  
 }  
 int insert_lit(char str[])  
 {  
   int i=0;  
   while(strcmp(lit_tab[i].token,NULL)!=0)  
   {  
     i++;  
   }  
   strcpy(lit_tab[i].token,str);  
   return i;  
 }  
 int search_iden(char str[])  
 {  
   int i=0;  
    while(strcmp(iden_tab[i].token,NULL)!=0)  
    {  
     if(strcmp(iden_tab[i].token,str)==0)  
       return i;  
     i++;  
    }  
    return -1;  
 }  
 int insert_iden(char str[])  
 {  
   int i=0;  
   while(strcmp(iden_tab[i].token,NULL)!=0)  
   {  
     i++;  
   }  
   strcpy(iden_tab[i].token,str);  
   return i;  
 }  
 int search(char str[])  
 {  
   int i=0;  
   while(strcmp(terminal[i],NULL)!=0)  
   {  
     if(strcmp(terminal[i],str)==0 )  
       return i;  
     i++;  
   }  
   return -1;  
 }  
 void ust_insert(char token[],char type,int pos)  
 {  
   strcpy(ust[ust_ptr].token,token);  
   ust[ust_ptr].type=type;  
   ust[ust_ptr].pos=pos;  
   ust_ptr++;  
 }  
 void main()  
 {  
   FILE *fp;  
   clrscr();  
   fp=fopen("lex.txt","r");  
   if(fp==NULL)  
   {  
     printf("File Not Found");  
     return;  
   }  
   char str[max],token[max];  
   int i,j;  
   while( !feof(fp) )  
   {  
     fgets(str,max,fp);  
     i=0;  
     strcpy(token,NULL);  
     while(str[i]!='\n' && str[i]!=NULL)  
     {  
       while(str[i]==' ' || str[i]=='\t')  
         i++;  
       j=0;  
       if(str[i]=='/')  
       {  
         if(str[i+1]=='/')  
         {  
           fgets(str,max,fp);  
           continue;  
         }  
         else if(str[i+1]=='*')  
         {  
           i+=2;  
           while(str[i]!='*' && str[i+1]!='/')  
           {  
             if(str[i]=='\n')  
             {  
               fgets(str,max,fp);  
               i=0;  
             }  
             i++;  
           }  
           i+=2;  
         }  
       }  
       while(str[i]!=' ' && str[i]!='\t' && str[i]!='\n')  
       {  
         if(str[i-1]=='"' && str[i]!=')')  
         {  
           while(str[i]!='"')  
           {  
             token[j]=str[i];  
             j++;i++;  
           }  
           break;  
         }  
         token[j]=str[i];  
         j++;  
         i++;  
         if(ispunct(str[i]))  
             //if(str[i]=='(' || str[i]==')' ||str[i]==';' ||str[i]==','||str[i]=='+'||str[i]=='='||str[i]=='-'||str[i]=='/'||str[i]=='*')  
           break;  
         if(ispunct(str[i-1]) )  
             //if(str[i-1]==','||str[i-1]=='='||str[i-1]=='/'||str[i-1]=='+'||str[i-1]=='-'||str[i-1]=='*')  
           break;  
       }  
       token[j]=NULL;  
       int x;  
       int l=strlen(token);  
       int pos;  
       x=search(token);  
       if(x!=-1)  
         ust_insert(token,'T',x);  
       else if(str[i-l-1]!='"' && !(token[0]>='0'&& token[0]<='9')&&strcmp(token,NULL)!=0 )  
       {  
         x=search_iden(token);  
         if(x==-1)  
         {  
           pos=insert_iden(token);  
           ust_insert(token,'I',pos);  
         }  
         else  
           ust_insert(token,'I',x);  
       }  
       else if( strcmp(token,NULL)!=0)  
       {  
         x=search_lit(token);  
         if(x==-1)  
         {  
           pos=insert_lit(token);  
           ust_insert(token,'L',pos);  
         }  
         else  
           ust_insert(token,'L',x);  
       }  
     }  
   }  
   print_ter();  
   print_lit();  
   print_iden();  
   print_ust();  
   getch();  
 }

 

Other Projects to Try:

  1. Prims algorithm Code in C Language
  2. Breadth First and Depth First Search C Language
  3. Dijkstra Algorithm in C Language
  4. BFS AND DFS Algorithm using C Language
  5. Lexical Analyzer for Subset of C

Filed Under: System Programming

Krushkals algorithm Code in C Language

May 4, 2011 by ProjectsGeek Leave a Comment

Krushkals algorithm Code in C Language Code
 #include  
 #include  
 #define max 50  
 void create_heap(int arr[][3],int n)  
 {  
   int k,heap,j;  
   int temp[3];  
   for(int i=(n/2)-1;i>=0;--i)  
   {  
     k=i;  
     temp[0]=arr[k][0];  
     temp[1]=arr[k][1];  
     temp[2]=arr[k][2];  
     heap=0;  
     while( heap!=1 && ( (2*k +1)      {  
       j=2*k+1;  
       if(j<n-1) <br="">       if(arr[j][2]>arr[j+1][2])  
         j++;  
       if(arr[k][2]<arr[j][2]) <br="">         heap=1;  
       else  
       {  
         arr[k][0]=arr[j][0];  
         arr[k][1]=arr[j][1];  
         arr[k][2]=arr[j][2];  
         k=j;  
         heap=0;  
       }  
     }  
     arr[k][0]=temp[0];  
     arr[k][1]=temp[1];  
     arr[k][2]=temp[2];  
   }  
 }  
 void input(int arr[][3])  
 {  
   char ch;  
   int s,d,w;  
   int i=0;  
   while(1)  
   {  
     printf("Do you want to enter any edge?:");  
     flushall();  
     scanf("%c",&ch);  
     if(ch=='n'||ch=='N')  
       break;  
     printf("Source:");  
     flushall();  
     scanf("%d",&s);  
     printf("Destination:");  
     flushall();  
     scanf("%d",&d);  
     printf("Weight:");  
     flushall();  
     scanf("%d",&w);  
     arr[i][0]=s;  
     arr[i][1]=d;  
     arr[i++][2]=w;  
   }  
 }  
 void heap_delete(int arr[][3],int *n)  
 {  
   (*n)--;  
   arr[0][0]=arr[*n][0];  
   arr[0][1]=arr[*n][1];  
   arr[0][2]=arr[*n][2];  
   create_heap(arr,*n);  
 }  
 int find(int i,int parent[20])  
 {  
   while(parent[i]!=-1)  
     i=parent[i];  
   return i;  
 }  
 void main()  
 {  
   clrscr();  
   int n;  
   printf("Enter the no of veritces\n");  
   int edge[max][3],parent[max];  
   scanf("%d",&n);  
   input(edge);  
   int t[3];  
   //create_heap(edge,n);  
   create_heap(edge,n);  
   int u,v;  
   int n1=n;  
   int result[max][3];  
   for(int i=0;i<n;++i) <br="">     parent[i]=-1;  
   for(i=0;i<n1-1;++i) <br="">   {  
     t[0]=edge[0][0];  
     t[1]=edge[0][1];  
     t[2]=edge[0][2];  
     u=find(t[0],parent);  
     v=find(t[1],parent);  
     if(u!=v)  
     {  
       parent[u]=v;  
       result[i][0]=t[0];  
       result[i][1]=t[1];  
       result[i][2]=t[2];  
     }  
     heap_delete(edge,&n);  
   }  
   printf("S\tD\tW\n");  
   for(i=0;i<n1-1;++i) <br="">     printf("%d\t%d\t%d\n",result[i][0],result[i][1],result[i][2]);  
   getch();  
 }

 

 

Other Projects to Try:

  1. Hash table code in C Language
  2. Prims algorithm Code in C Language
  3. Hoffmans algorithm in C Language
  4. Dijkstra Algorithm in C Language
  5. BFS AND DFS Algorithm using C Language

Filed Under: Design and Analysis of Algorithms

Text or Screen Editor in C++ Language

May 4, 2011 by ProjectsGeek Leave a Comment

Text or Screen Editor in C++ Language

Write a program in C++ Language to implement a Text or Screen Editor which can edit the entered text on screen.Program should make a file which will be used for storing text .

Text or Screen Editor in C++ Language Code

 #include  
 #include  
 #include  
 #define left 21  
 #define top 7  
 #define right 59  
 #define bottom 24  
 void main()  
 {  
   clrscr();  
   window(left,top-1,right,bottom);  
   char buff[100][40];  
   FILE *fp;  
   fp=fopen("editfile.txt","w");  
   clrscr();  
   cprintf("F1 New F2 SAVE F3 OPEN F4 EXIT\n\r");  
   int x=wherex();  
   int y=wherey();  
   //gotoxy(x,y);  
   char ch;  
   int row;  
   int col;   
   int i;  
   do  
   {  
     flushall();  
     ch=getch();  
     int i=0,j=0;  
     if(ch==0)  
     {  
       ch=getch();  
     }  
     //int  
     char c;  
     switch(ch)  
     {  
       case '='://open  
         fp=fopen("editfile.txt","r");  
         i=0;  
         clrscr();  
         while(i<15)  
         {  
           c=fgetc(fp);  
           if(c=='\n')  
           {  
             i++;  
           }  
           cprintf("%c",c);  
         }  
         getch();  
       case '<':  
          //save  
         i=1;  
         fp=fopen("editfile.txt","w");  
         while(i<16)  
         {  
           j=1;  
           while( buff[i][j]!='~' && buff[i][j]!='\r')  
           {  
             fputc(buff[i][j],fp);  
             j++;  
           }  
           fputc('\n',fp);  
           i++;  
         }  
         fputc('\0',fp);  
         getch();  
         clrscr();  
         gotoxy(x,y);  
         cprintf("F1 New F2 SAVE F3 OPEN F4 EXIT\n\r");  
         break;  
       case ';': //NEW FILE  
         //cprintf("yo");  
         clrscr();  
         cprintf("F1 New F2 SAVE F3 OPEN F4 EXIT\n\r");  
         cprintf("NEW FILE CREATED\n\r");  
         row=1;  
         col=0;  
         i=0;  
         while(i<15)  
         {  
           strcpy(buff[i],NULL);  
           buff[i][0]='~';  
           buff[i][1]='~';  
           buff[i][2]=NULL;  
           i++;  
         }  
         break;  
       case '>'://exit t  
         break;  
       case '\r':// return character next line  
         row++;  
         col=0;  
         gotoxy(x+col,y+row);  
         break;  
       case 'P':  
         row++;  
         gotoxy(x+col,y+row);  
         break;  
       case 'H':  
         if(row!=1)  
         {  
           row--;  
           gotoxy(x+col,y+row);  
         }  
         break;  
        case 'M':  
         col++;  
         if(col==39)  
         {  
           col=0;  
           row++;  
         }  
         gotoxy(x+col,y+row);  
         break;  
        case 'K':  
         col--;  
         if(col==-1)  
         {  
           col=0;  
         }  
         gotoxy(x+col,y+row);  
         break;  
        case '\b':  
          if((col-1)==-1)  
          {  
           break;  
          }  
          if(buff[row][col+1]=='~')  
          {  
           buff[row][col]='~';  
           buff[row][col+1]=NULL;  
           gotoxy(x+col-1,y+row);  
           cprintf(" ");  
           gotoxy(x+col-1,y+row);  
           col--;  
          }  
         else  
          {  
           i=strlen(buff[row]);  
           j=col;  
           gotoxy(x+col-1,y+row);  
           while(j<=i)  
           {  
             buff[row][j]=buff[row][j+1];  
             if(buff[row][j+1]=='~')  
               break;  
             cprintf("%c",buff[row][j+1]);  
             j++;  
           }  
           cprintf(" ");  
           buff[row][i-1]=NULL;  
           gotoxy(x+col-1,y+row);  
           col--;  
          }  
         break;  
        case 'S':  
        if(buff[row][col+1]=='~')  
        {  
         buff[row][col]='~';  
         buff[row][col+1]=NULL;  
         gotoxy(x+col-1,y+row);  
         cprintf(" ");  
         gotoxy(x+col,y+row);  
        }  
        else  
        {  
         i=strlen(buff[row]);  
         j=col+1;  
         gotoxy(x+col,y+row);  
         while(j<=i)  
         {  
           buff[row][j]=buff[row][j+1];  
           if(buff[row][j+1]=='~')  
             break;  
           cprintf("%c",buff[row][j+1]);  
           j++;  
         }  
         cprintf(" ");  
         buff[row][i-1]=NULL;  
         gotoxy(x+col,y+row);  
        }  
         break;  
       default:  
         //row=where  
         col++;  
         if(col==39)  
         {  
           row++;  
           col=0;  
           gotoxy(x+col,y+row);  
         }  
         i=strlen(buff[row]);  
         if( (strlen(buff[row])-1)         {  
           for(i=strlen(buff[row])-1;i<col;++i) <br="">           {  
             buff[row][i]=' ';  
           }  
         }  
           //  else  
          //  col++;  
         buff[row][col+1]='~';  
         buff[row][col]=ch;  
         buff[row][col+2]=NULL;  
         cprintf("%c",ch);  
     }  
   }while(ch!='>');  
 }

 

Other Projects to Try:

  1. How to Implement Hash Table using C language
  2. Hash table code in C Language
  3. Single Link List code using C Language
  4. Applet Text Editor
  5. Text Editor in Java Project

Filed Under: System Programming

ASCII-Binary conversion in Assembly Language

April 26, 2011 by ProjectsGeek Leave a Comment

ASCII-Binary conversion in Assembly Language

Write a Assembly program for ASCII-Binary conversion with proper output . First of all do ASCII-Gray conversion by Dividing  the ASCII number by 2 until the quotient is 0 . 

 

Algorithm for ASCII-Binary conversion


Step I
         :    Get the number whose binary code equivalent is to be found.

Step II        :    Initialize count in CL = 08 H
Step III      :    Divide the number by 2 i.e. shift the number by 1 it to the left.
Step III      :    Display the bit shifted in carry.
Step IV      :    Decrement count
Step V       :    Check if count =0 ?
Step VI      :    If yes go to step  VII else go to step III.
Step VII     :    Stop.

ASCII-Binary conversion

Program Code for ASCII-Binary conversion

 .model small  
 .data  
 a db 0AH  
 .code  
         mov      ax, @data      ; Initialize data section  
      mov      ds, ax  
      mov      al, a             ; Load number1 in al  
      mov      cl , 08H  
      mov      ah, 00h           ; ah=00  
 up :     shl      al, 01h       ; divide the number by 2   
                 and SHL gives the same result         
      mov      bl, al                 
      mov      al, 00H  
      adc      al, 30h  
      mov      dl, al  
      mov      ah, 02h  
      int      21h  
      mov      al,bl  
      dec      cl  
      jnz      up  
      mov      ah, 4cH            ; Terminate Program  
      int      21H  
      end

How to Run this Program
For Running this program you should have installed Tasm on you computer . If you have not installed Tasm  yet please install from Here .

Result : 0000 1010

Other Projects to Try:

  1. Assembly Programs
  2. Add 8 Bit BCD Numbers
  3. BCD to decimal Conversion in Assembly Language
  4. Hex to BCD Conversion in Assembly Language Code
  5. How to convert Binary to Gray conversion

Filed Under: Assembly Codes Tagged With: Assembly Codes

GCD of Two Numbers program in Assembly Language

April 26, 2011 by ProjectsGeek Leave a Comment

GCD of Two Numbers program in Assembly Language

Write  a Program to find the GCD of Two Numbers  in Assembly Language . Program should load two registers with two Numbers  and then apply the logic for GCD of two Numbers . GCD of two numbers is performed by dividing the greater number by the smaller number till the remainder is zero. If it is zero, the divisor is the GCD if not the remainder and the divisor of the previous division are the new set of two numbers. The process is repeated by dividing greater of the two numbers by the smaller number till the remainder is zero and GCD is found.

 

Algorithm for  GCD of Two Numbers

 

Step I            :     Initialize the data segment.
Step II          :     Load AX and BX registers with the operands.
Step III        :     Check if the two numbers are equal. If yes goto step X, else goto step IV.
Step IV         :     Is number 1 > number 2 ? If yes goto step VI else goto step V.
Step V          :     Exchange the contents of AX and BX register, such that AX contains the bigger number.
Step VI         :     Initialize DX register with 00H.
Step VII       :     Perform the division operation (contents of AX / contents of BX).
Step VIII     :     Check if there is remainder. If yes goto step IX, else goto step X.
Step IX        :     Move the remainder into AX register and goto step IV.
Step X          :     Save the contents of BX as GCD.
Step XI        :     Display the result.
Step XII       :     Stop.

GCD of Two Numbers  Algorithm Snapshot

GCD of Two Numbers

Program code for GCD of Two Numbers 

 

.model small  
 .stack 100  
 .data  
 no1  dw 0120  
 no2  dw 0090  
 gcd dw 0h  
 .code  
      mov      ax,@data          ; initialize DS  
      mov      ds, ax       
      mov      ax, no1           ; get the first number  
      mov      bx, no2           ; get the second number  
 again:      cmp      ax, bx     ; check if nos are equal  
          je      endd           ; if equal, save the GCD  
      jb      exchg              ; if no,   
                                 ; is AX                                 ; if yes interchange   
 l2:     mov      dx, 0  
      div      bx                ; check if ax is   
                                 ; divisible by bx  
      cmp      dx, 0     ;  
      je      endd  
      mov      ax, dx            ; mov the remainder   
                                 ; as no1 data  
      jmp      again  
 exchg :      xchg      ax, bx jmp l2  
 endd :      mov      gcd, bx  
      mov      ch, 04h           ; Count of digits to be   
                ; displayed  
      mov      cl, 04h           ; Count to roll by 4 bits  
 l12:     rol      bx, cl        ; roll bl so that msb   
                ; comes to lsb   
         mov      dl, bl         ; load dl with data   
                ; to be displayed  
         and      dl, 0fH        ; get only lsb  
         cmp      dl, 09         ; check if digit is 0-9   
                ; or letter A-F  
         jbe      l4  
         add      dl, 07         ; if letter add 37H else   
                ; only add 30H  
 l4:       add      dl, 30H  
         mov      ah, 02         ; INT 21H   
                ; (Display character)  
         int      21H  
         dec      ch             ; Decrement Count  
         jnz      l12                                
      mov      ah, 4ch  
      int      21h  
 end

How to Run this Program

 

For Running this program you should have installed Tasm on you computer . If you have not installed Tasm  yet please install from Here .

C:\programs>tasm gcd.asm
Turbo Assembler  Version 3.0  Copyright (c) 1988, 1991 Borland International
Assembling file:   gcd.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  437k
C:\programs>tlink gcd
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
C:\programs>gcd
001E

Other Projects to Try:

  1. 2s Complement of a Numbers Assembly Code
  2. Add 8 Bit BCD Numbers
  3. Program to Add Two 16 Bit Numbers Assembly Code
  4. Mask Upper Nibble in Assembly Language Program code
  5. Multiply Two 8 Bit Numbers in Assembly Language

Filed Under: Assembly Codes Tagged With: Assembly Codes

Operation on Strings in Assembly Language

April 26, 2011 by ProjectsGeek Leave a Comment

Operation on Strings in Assembly Language

Write a Program for Operation on Strings in Assembly Language. Using Macro display the Menu for entering string, calculate length, reverse, palindrome and exit. Accept the choice from user using INT 21H function 01H. 
Choice = 1: Call procedure for accepting string. Using interrupt INT 21H, function 0AH accept the string and end procedure. Return back to display Menu.
Choice = 2: Call procedure for finding length of the string. Display length and return  back to display Menu.
Choice = 3: Call procedure to reverse the string. Display the reverse string and return back to display Menu.
Choice = 4: Call procedure to check if entered string is palindrome. If palindrome displays, the string is a palindrome, otherwise display String is not a palindrome.
Choice = 5: Terminate the program. If any other key is pressed display invalid choice. 

Algorithm for Operation on Strings

Step I    :    Initialize the data and stack memory.
Step II    :    Using Macro display Menu.
        1.    Accept
        2.    Length
        3.    Reverse
        4.    Palindrome
        5.    Exit.
Step III    :    Accept choice from user using INT 21H, function 01H.
Step IV    :    IS choice = 1  jump to step XI else goto step V.
Step V    :    IS choice = 2 jump to step XIV else goto step VI.
Step VI    :    IS choice = 3 jump to step XVII else goto step VII.
Step VII    :    IS choice = 4 jump to step XX else goto step VIII.
Step VIII    :    IS choice = 5 jump to step XXIII else goto step IX.
Step IX    :    Display Wrong choice.
Step X    :    Jump to step II.
Step XI    :    Call procedure accept.
Step XII    :    Accept string using INT 21H, function 0AH.
Step XIII    :    Return to main program and goto step II.
Step XIV    :    Call procedure length.
Step XV    :    Calculate the length of string and display it using INT 21H, function 02H.
Step XVI    :    Return back to main program and jump to step II.
Step XVII    :    Call procedure reverse.
Step XVIII    :    Reverse the string and display it.
Step XIX    :    Return back to main program and jump to step II.
Step XX    :    Call procedure palindrome.
Step XXI    :    Check if string is palindrome. If yes display string is palindrome else string is not a palindrome.
Step XXII    :        Return back to main program and jump to step II.
Step XXIII    :    Terminate the program and stop.

Operation on Strings Assembly Language code
 TITLE  STRING OPERATIONS  
 MESS  MACRO MSG     ; DEFINITION OF MACRO MESS         
      MOV      AH, 09H  
      LEA      DX, MSG  
      INT      21H  
      ENDM  
 .MODEL SMALL   
 .STACK 100H  
 .DATA  
      STR1      DB 25 , ? , 25 DUP('$')   
      STR3      DB 25 , ? , 25 DUP('$')   
      MSG1      DB 0AH, 0DH, 'MENU $'  
      MSG21      DB 0AH, 0DH, '1.ACCEPT $'  
      MSG22      DB 0AH, 0DH, '2.LENGTH $'  
      MSG23      DB 0AH, 0DH, '3.REVERSE $'  
      MSG24      DB 0AH, 0DH, '4.PALINDROME $'  
      MSG25      DB 0AH, 0DH, '5.EXIT $'  
      MSG3      DB 0AH, 0DH, 'ENTER YOUR CHOICE : $'  
      MSG4      DB 0AH, 0DH, 'WRONG CHOICE $'  
      MSG5      DB 0AH, 0DH, 'ENTER THE STRING : $'  
      MSG6      DB 0AH, 0DH, 'STRING IS : $'  
      MSG7      DB 0AH, 0DH, 'LENGTH IS : $'  
      MSG8      DB 0AH, 0DH, 'THE STRING IS A PALINDROME  $'  
      MSG9      DB 0AH, 0DH, 'THE STRING IS NOT A PALINDROME  $'  
 .CODE   
 mov     ax,           @data     ; Intialize data and extra segment  
      mov           ds, ax  
      mov           es, ax  
 ak :     mess           msg1     ; display menu  
      mess           msg21  
      mess           msg22  
      mess           msg23  
      mess           msg24  
      mess           msg25  
      mess           msg3     ; accept choice  
      mov           ah, 01h  
      int           21h  
      mov           bl, al     ; Choice BL  
      cmp          bl, 31h     ; if choice=1  
      je           acc          ; Accept string  
      cmp           bl, 32h     ; if choice=2  
      je           len          ; Find lenth   
                                    ; of string  
      cmp           bl, 33h     ; if choice=3  
      je           rev          ; Reverse string  
      cmp           bl, 34h     ; if choice=4  
      je           pal          ; Check if string is   
                                    ; palindrome  
      cmp           bl, 35h     ; if choice=5  
      je           endd     ; exit  
      mess           msg4     ; Wrong Choice  
      jmp           ak  
 acc :     call           accept  
      jmp           ak  
 len :     call           lent  
      jmp           ak  
 rev :     call           reverse  
      jmp           ak  
 pal:     call           pall  
      jmp           ak  
 endd:     mov           ah, 4ch  
      int           21h  
 ;      accept      procedure                                            
      accept proc near  
      mess      msg5  
      mov      ah, 0ah     ; Accept String  
      lea           dx, str1  
      int           21h  
      RET  
 accept endp  
 ; length procedure    
 lent proc near     
      mess           msg7   
      mov           dl, str1+1     ; Dl contains length of String  
      or           dl, 30h  
      mov           ah, 02h          ; Display Length                           
      int           21h  
      ret   
 lent endp  
 ; reverse procedure    
 reverse proc near  
      mess           msg6  
      mov           ch, 00h  
      mov           cl, str1+1     ; Cl has length of string  
      sub           cl, 01h  
      lea           si, str1+2     ; DESTINATION STRING  
      lea           di, str1+2     ; DESTINATION STRING  
      repz           movsb          ; COPY TO TRAVERSE TILL END OF FIRST STR  
      mov           cl, str1+1         
      lea           di, str3+2     ; DESTINATION STRING  
 loop1:      mov           dx, [si]          ; dx contains rightmost character  
      mov           ah, 02h  
      int           21h          ; display character  
      mov           [di], dx          ; copy character to destination  
      dec           si  
      inc           di  
      dec           cl  
      cmp           cl, 00h  
      jne           loop1  
      ret  
 reverse endp  
 ; palindrome procedure    
 pall      proc           near  
      mess           msg6  
      mov           ah, 09h  
      lea           dx, str1+2     ; str1 contains original string  
      int           21h  
      call           reverse               ; str3 has reversed string   
      lea           di, str3+2  
      mov           ah, 00h  
      mov           dh, 00h  
      lea           si , str1+2  
      mov           cl, str1+1          ; CL contains Length of string  
 loop 2 :     mov           al, byte ptr[si]  
      mov           bl, byte ptr[di]  
      dec           cl                    ; Decrement count  
      cmp           cl, 00h  
      je           loopa  
      cmp           al, bl               ; Compare characters  
      je           loop3               ; if same goto loop3  
 loopa : cmp           cl, 00h               ; if checked all characters  
      je           loop4  
      mess           msg9               ; the strings are not same  
      jmp           loop5  
 loop4 : mess           msg8               ; the strings are same  
 loop5: ret  
 loop3 : inc           si  
      inc           di  
      jmp           loop2               ; now check next character  
      pall           endp  
 end

How to Run this Program 

For Running this program you should have installed Tasm on you computer . If you have not installed Tasm  yet please install from Here .

C:\programs>tasm str
Turbo Assembler  Version 3.0  Copyright (c) 1988, 1991 Borland International
Assembling file:   str.ASM
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  434k
C:\programs>tlink str
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
C:\programs>str
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE :  1
ENTER THE STRING :  college
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE :  2
LENGTH IS :  7
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE :  3
STRING IS :  egelloc
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE :  4
STRING IS :  college
STRING IS :  egelloc
THE STRING IS NOT A PALINDROME
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE : 1
ENTER THE STRING :  madam
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE :  4
STRING IS :  madam
STRING IS :  madam
THE STRING IS A PALINDROME

Other Projects to Try:

  1. String Operations with Pointers
  2. To Perform various String Operation in Java
  3. string operations such as Copy, Length, Reversing, Palindrome, Concatenation
  4. BCD to decimal Conversion in Assembly Language
  5. Multiply Two 8 Bit Numbers in Assembly Language

Filed Under: Assembly Codes Tagged With: Assembly Codes

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 126
  • Page 127
  • Page 128
  • Page 129
  • Page 130
  • Interim pages omitted …
  • Page 135
  • Go to Next Page »

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy