0% found this document useful (0 votes)
521 views8 pages

Palidrome in 8086

This document contains an algorithm and source code to check if a string is a palindrome in 8086 assembly language. The algorithm involves traversing the string from beginning and end, comparing characters at each index, and returning whether all characters match. The source code implements this by loading the start and end addresses, comparing characters in a loop until the indexes meet in the middle, and outputting the appropriate result string.

Uploaded by

Asmit Suragond
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
521 views8 pages

Palidrome in 8086

This document contains an algorithm and source code to check if a string is a palindrome in 8086 assembly language. The algorithm involves traversing the string from beginning and end, comparing characters at each index, and returning whether all characters match. The source code implements this by loading the start and end addresses, comparing characters in a loop until the indexes meet in the middle, and outputting the appropriate result string.

Uploaded by

Asmit Suragond
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Introduction

8086 program to check whether a string is palindrome or not


Problem: Write an 8086 program to check whether a given
string is palindrome or not.

Examples:

Input String: "MAM"


Output: String is palindrome

Input String: "VVP"


Output: String is not palindrome
Explanation:
Algorithm

1. Create a string
2. Traverse to the end of the string
3. Get the address of the end of the string, DI
4. Load the starting address of the string, SI
5. Compare the value stored at the address
6. Increment the pointer, SI
7. Decrements the pointer, DI
8. Compare again the value stored at si and di
9. Repeat the steps until SI<=DI
10. If all the characters match print string is palindrome
else print not palindrome
SOURCE CODE

.MODEL SMALL

.STACK 100H

.DATA

; The string to be printed

STRING DB 'mam', '$'

STRING1 DB 'String is palindrome', '$'

STRING2 DB 'String is not palindrome', '$'

.CODE
MAIN PROC FAR

MOV AX, @DATA

MOV DS, AX

; check if the string is;

;palindrome or not

CALL Palindrome

;interrupt to exit

MOV AH, 4CH

INT 21H

MAIN ENDP

Palindrome PROC

; load the starting address

; of the string

MOV SI,OFFSET STRING

; traverse to the end of;

;the string

LOOP1 :

MOV AX, [SI]

CMP AL, '$'

JE LABEL1

INC SI
JMP LOOP1

;load the starting address;

;of the string

LABEL1 :

MOV DI,OFFSET STRING

DEC SI

; check if the string is plaindrome;

;or not

LOOP2 :

CMP SI, DI

JL OUTPUT1

MOV AX,[SI]

MOV BX, [DI]

CMP AL, BL

JNE OUTPUT2

DEC SI

INC DI

JMP LOOP2

OUTPUT1:

;load address of the string

LEA DX,STRING1
; output the string;

;loaded in dx

MOV AH, 09H

INT 21H

RET

OUTPUT2:

;load address of the string

LEA DX,STRING2

; output the string

; loaded in dx

MOV AH,09H

INT 21H

RET

Palindrome ENDP

END MAIN
OUTPUT

You might also like