An Assembly program to check if two strings are reverse of each other – IGNOU MCA Assignment 2013

By | April 14, 2014

MASTER OF COMPUTER APPLICATIONS
Course Code : MCSL-012
Course Title : Computer Organisation and Assembly Language Programming
Assignment Number : MCA(1)/012/Assign/2013 and BCA(II)/012/Assign/2013

 

Write a program in 8086 assembly Language (with proper comments) to find if the two given strings of length 5 are reverse of each other. You may assume that both the strings are available in the memory. Make suitable assumptions, if any

 

DATA SEGMENT
    STR1 DB “NITIN”
    STR2 DB “GITIN”
    MSG1 DB 10,13,’STRING IS NOT A PALINDROME $’ 
    MSG2 DB 10,13,’STRING IS A PALINDROME $’
DATA ENDS

DISPLAY MACRO MSG
    MOV AH,9
    LEA DX,MSG
    INT 21H
ENDM   

CODE SEGMENT
    ASSUME CS:CODE,DS:DATA
START:
        MOV AX,DATA
        MOV DS,AX                
      
        LEA SI,STR1
        LEA DI,STR2
        ADD DI,4
       
        MOV CX,5
CHECK:
        MOV AL,[SI]
        CMP [DI],AL
        JNE NOTPALIN
        DEC DI
        INC SI
        LOOP CHECK     
       
        DISPLAY MSG2
        JMP EXIT
NOTPALIN:
        DISPLAY MSG1
               
EXIT:   MOV AH,4CH
        INT 21H
CODE ENDS
END START

program code :

  1. DATA SEGMENT
  2.     STR1 DB "NITIN"
  3.     STR2 DB "GITIN"
  4.     MSG1 DB 10,13,'STRING IS NOT A PALINDROME $' 
  5.     MSG2 DB 10,13,'STRING IS A PALINDROME $'
  6. DATA ENDS
  7. DISPLAY MACRO MSG
  8.     MOV AH,9
  9.     LEA DX,MSG
  10.     INT 21H
  11. ENDM   
  12. CODE SEGMENT
  13.     ASSUME CS:CODE,DS:DATA
  14. START:
  15.         MOV AX,DATA
  16.         MOV DS,AX                
  17.       
  18.         LEA SI,STR1
  19.         LEA DI,STR2
  20.         ADD DI,4
  21.        
  22.         MOV CX,5
  23. CHECK:
  24.         MOV AL,[SI]
  25.         CMP [DI],AL
  26.         JNE NOTPALIN
  27.         DEC DI
  28.         INC SI
  29.         LOOP CHECK     
  30.        
  31.         DISPLAY MSG2
  32.         JMP EXIT
  33. NOTPALIN:
  34.         DISPLAY MSG1
  35.                
  36. EXIT:   MOV AH,4CH
  37.         INT 21H
  38. CODE ENDS
  39. END START

Screen shots :-

Asm_program_String_is_Reverse

Output when Both Strings are Same :-

Asm_program_String_is_Reverse_Output1

Output when Both Strings are Not Same :-

Asm_program_String_is_Reverse_Output2

Leave a Reply