At last! This head-breaking palindrome program is done…
; –ask string from user–
mov ah,0ah
lea dx,parameter
int 21h
mov ah,02
mov dl,0ah
int 21h
mov dl,0dh
int 21h
;–intialize–
mov cx, 0 ; or xor cx, cx –for making cx=0
lea si, namefield ; load address of namespace
mov cl, [actlen] ; cl refers to the length of the string
dec cl ; strings start at 0 and ends at [actlen]-1
lea di, namefield ; load address of namespace
add di, cx ; di now points to the last character of string
mov ah, 09 ; print string function
compare:
mov cl, [si] ; get character from si
mov ch, [di] ; get character from di
cmp cl, ch ; compare two characters
jne stop ; if not equal, not palindrome
inc si
dec di
cmp di, si ; check if si>di
jns compare
lea dx, pal
int 21h
jmp exit
stop:
lea dx, notpal
int 21h
exit:
int 20h
parameter label byte
maxlen db 0FF
actlen db ?
namefield db 0FF dup(’$')
pal db ‘This string is a palindrome$’
notpal db ‘This string is not a palindrome$’