8086 Assembly Program to Check if String is Palindrome or not

DATA SEGMENT

BLOCK1 DB 'MALAYALAM'
MSG1 DB "IT IS PALINDROME $"
MSG2 DB "IT IS NOT PALINDROME $"
PAL DB 00H

DATA ENDS

PRINT MACRO MSG

MOV AH,09H
LEA DX,MSG
INT 21H
INT 3H

ENDM

EXTRA SEGMENT

BLOCK2 DB 9 DUP(?)
EXTRA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA
START: MOV AX,DATA
MOV DS,AX
MOV AX,EXTRA
MOV ES,AX
LEA SI,BLOCK1
LEA DI,BLOCK2+8
MOV CX,00009H
BACK: CLD
LODSB
STD
STOSB
LOOP BACK
LEA SI,BLOCK1
LEA DI,BLOCK2
MOV CX,0009H
CLD
REPZ CMPSB
JNZ SKIP
PRINT MSG1
SKIP: PRINT MSG2
CODE ENDS
END START

Output

C:\TASM>masm AMPE7.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987.  All rights reserved.

Object filename [AMPE7.OBJ]:
Source listing  [NUL.LST]:
Cross-reference [NUL.CRF]:

  49534 + 414818 Bytes symbol space free

      0 Warning Errors
      0 Severe  Errors

C:\TASM>link AMPE7.obj

Microsoft (R) Overlay Linker  Version 3.60
Copyright (C) Microsoft Corp 1983-1987.  All rights reserved.

Run File [AMPE7.EXE]:
List File [NUL.MAP]:
Libraries [.LIB]:
LINK : warning L4021: no stack segment

C:\TASM>debug AMPE7.exe
-g
IT IS PALINDROME
AX=0924  BX=0000  CX=0000  DX=0009  SP=0000  BP=0000  SI=0009  DI=0009
DS=14A4  ES=14A8  SS=14A4  CS=14A9  IP=0033   NV UP EI PL ZR NA PE NC
14A9:0033 CC            INT     3
-d 14A4:0000
14A4:0000  4D 41 4C 41 59 41 4C 41-4D 49 54 20 49 53 20 50   MALAYALAMIT IS P
14A4:0010  41 4C 49 4E 44 52 4F 4D-45 20 24 49 54 20 49 53   ALINDROME $IT IS
14A4:0020  20 4E 4F 54 20 50 41 4C-49 4E 44 52 4F 4D 45 20    NOT PALINDROME
14A4:0030  24 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   $...............
14A4:0040  4D 41 4C 41 59 41 4C 41-4D 00 00 00 00 00 00 00   MALAYALAM.......
14A4:0050  B8 A4 14 8E D8 B8 A8 14-8E C0 8D 36 00 00 8D 3E   ...........6...>
14A4:0060  08 00 B9 09 00 FC AC FD-AA E2 FA 8D 36 00 00 8D   ............6...
14A4:0070  3E 00 00 B9 09 00 FC F3-A6 75 09 B4 09 8D 16 09   >........u......
*/

Leave a Reply

Your email address will not be published. Required fields are marked *