Palidrome in 8086
Palidrome in 8086
Palidrome in 8086
Examples:
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
.CODE
MAIN PROC FAR
MOV DS, AX
;palindrome or not
CALL Palindrome
;interrupt to exit
INT 21H
MAIN ENDP
Palindrome PROC
; of the string
;the string
LOOP1 :
JE LABEL1
INC SI
JMP LOOP1
LABEL1 :
DEC SI
;or not
LOOP2 :
CMP SI, DI
JL OUTPUT1
MOV AX,[SI]
CMP AL, BL
JNE OUTPUT2
DEC SI
INC DI
JMP LOOP2
OUTPUT1:
LEA DX,STRING1
; output the string;
;loaded in dx
INT 21H
RET
OUTPUT2:
LEA DX,STRING2
; loaded in dx
MOV AH,09H
INT 21H
RET
Palindrome ENDP
END MAIN
OUTPUT