• 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

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

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

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