Operation on Strings in Assembly Language

Posted on

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

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

Source projectgeek.com