Palindrome problem

From: Tin Phan (tin22phan_at_yahoo.com)
Date: 12/30/03


Date: 29 Dec 2003 16:11:46 -0800

Hello, I have wrote this palindrome assignment and everything work
"OK". However, somehow I cannot make the comparision between the two
end of the characters to work properly. When I tried to compare al,
byte ptr buffer[bx], the output alway come out not equal. I think the
read in of buffer[si] is the problem. I hope some of you outhere know
the problem is since I'm new at assembly language. Here is the code:
mov dx,offset buffer ;dx = address of buffer
        mov cx,78 ;cx = max number of bytes to read
        mov bx,0 ;bx = stdin device
        mov ah,3fh ;ah = read function code
        int 21h ;read from keyboard
        
        sub ax,2 ;ax = no. bytes read
        
;=================================================================================
; Note also that register ax contains the number of bytes that were
read. The
; program work; however, there is a problem with the comparing part.
;=================================================================================
        mov cx,ax ;cx = count
        xor si,si ;zero out the SI register
L1:
         mov bx,cx ;bx = the loop decrement
         cmp si,bx
         jg NotPald ;Palindrom # = si>bx
         je P1 ;display Palindrom message
         mov al,byte ptr buffer [si] ;al = content of buffer[si]
         cmp al,byte ptr buffer [bx] ;buffer [si] == buffer [bx]
         jne NotPald ;Not a palindrom
         inc si
         loop L1
         
 NotPald:
         lea dx,Npal ;dx = not Palindrom,display
         mov ah,09h
         int 21h
         jmp done
 P1:
         lea dx,Pal ;dx = Palindrom,display
         mov ah,09h
         int 21h
         jmp done
         
                                                Thanks.