Expt 9
Expt 9
EXP.No: 09 Date:
PALINDROME
Aim:
APPARATUS:
MASM software
Personal computer
Portsused: None
Algorithm:
1. Start
2. Initialize the segments used
3. Initialize the Input & Output variables in the Data segment
4. End the data segment
5. Start the code segment
6. Initialize the data segment on code segment
7. Clear the CX Register
8. Assign the Given word to the SI Register
9. Count is assigned to the CX register and count moved to BX register
10. Store the 1st letter of the word in AL register from SI register
11. Store the last letter of the word in AH register from BX register
12. Compare the both letters
13. If both letters are Equal then go to next letters otherwise display the message “GIVEN
WORD IS NOT PALINDROME”.
14. Increment the SI and Decrement the count
15. Again compare the letters till the count is zero.
16. After comparing the all letters, if comparison is equal then display the message
“GIVEN WORD IS NOT PALINDROME”
17. Stop
PROGRAM:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
PALIN DB "RADER","$"
MSG1 DB "GIVEN WORD IS PALINDROME","$"
MSG2 DB "GIVEN WORD IS NOT PALINDROME","$"
COUNT EQU 04H
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
XOR CX,CX
LEA SI,PALIN
MOV CL,COUNT
BACK: MOV CL,[SI]
MOV BX,CX
MOV AH,[BX]
CMP AL,AH
JE OK
LEA DX,MSG2
MOV AH,09H
INT 21H
JMP OVER
OK: INC SI
DEC CL
JNZ BACK
LEA DX,MSG1
MOV AH,09H
INT 21H
OVER: MOV AH,4CH
INT 21H
CODE ENDS
END START
CODE TABLE:
Segment Offset
Base Address
Address
0B52 0000 B84E0B MOV AX,0B4E Initialization of Data
0B52 0003 8ED8 MOV DS,AX segment
Procedure:
Result:Check the given word is PALINDROM or not and results are observed using MASM