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 :

[codesyntax lang=”asm” lines=”normal”]

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

[/codesyntax]

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