.code
>
> start:
> mov ax,03h
> int 10h
> mov ax,seg msg1
> mov ds,ax
> mov dx,offset msg1
> mov ah,09h
> int 21h
> mov si,offset str
> read:
> mov ah,01h
> int 21h
> cmp al,0dh
> je next
> mov [si],al
> inc si
> inc count
> jmp read
> next:
> mov di,offset str
> mov al,count
> mov cl,al
> mov ch,00h
> dec si
> check:
> mov al,[si]
> cmp al,[di]
> jne nt
> dec si
> inc di
> loop check
> mov ax,seg msg2
> mov ah,09h
> int 21h
> jmp exit
> nt:
> mov ax,seg msg3
> mov ds,ax
> mov dx,offset msg3
> mov ah,09h
> int 21h
> exit:
> mov ax,4c00h
> int 21h
> END start
This is part of 8086 masm code for checking whether a string is a palindrome or not.msg1 is 'Enter string',msg2 is 'string is palindrome',msg3 is 'string is not palinrome' What does 'cmp al,0dh' performs in this code?
It's not mentioned where this code came from, but it's incomplete (e.g. as Mario points out: no
next:
label) present. But we can piece it together:So all this code does is display a message to the user prompting them to enter a string, terminated by a line feed (0dh) and it reads the string in (to location
str
). It also provides the number of characters read incount
. Wherestr
,count
, andmsg1
are defined aren't given.