Is the given string a palindrome
A palindrome is a word, number, phrase or other sequence of characters that reads the same backwards as forwards. Examples: civic, deed, madam, racecar.
Program source code
title .model small .stack 100h data segment public string db "madam" strlen equ ($-string) true db "True$" false db "False$" data ends code segment public assume ds:data, cs:code main proc mov ax, seg data ; Get the data segment address and store it in ax mov ds, ax ; Pass the data segment address from ax to ds mov cx, strlen ; Copy the value of the strlen variable into the cx register lea si, ds:[string] ; Load the address of the string variable into the source register ds:si mov di, si ; Copy the value of the source register si into the destination register di add di, cx ; Add cx to di. The pointer will point to the end of the string + 1 dec di ; Decrement the di index by 1 shr cx, 1 ; Divide the string length by 2 MainLoop: lodsb ; Load the byte at address ds:si into the al register. SI++ cmp al, byte ptr[di] ; Compare the value in al with the value in the destination register di jne NotPalindrome ; If ZF=0, jump to the NotPalindrome label dec di ; Decrement the di index by 1. Look at the next character from the end of the string loop MainLoop ; Loop while CX≠0 mov ah, 09h ; Copy the string output function number into ah lea dx, ds:[true] ; Load the address of the true variable into the ds:dx registers int 21h ; Call the interrupt jmp Done ; Jump unconditionally to the Done label NotPalindrome: mov ah, 09h ; Copy the string output function number into ah lea dx, ds:[false] ; Load the address of the false variable into the ds:dx registers int 21h ; Call the interrupt Done: mov ax, 4C00h ; Copy the termination function number into ah and the value into al int 21h ; Call the interrupt main endp code ends end main
True
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".