问题比较字符串中的字母 [Assembly]

Issue comparing letters in a string [Assembly]

我正在尝试创建一个程序来遍历字符串并检查它是否是回文。

我目前正在测试的单词是racecar,但是当我运行下面的代码时,它会自动判断第一个和最后一个值不一样.

这只是将错误的寄存器输入到循环中的情况,还是不止于此?

main proc
mov edi, SIZEOF myWord- TYPE myWord ;length of string - type of data
mov ecx, LENGTHOF myWord/ 2  ;loop (N / 2) times
mov esi,OFFSET myWord ;beginning of string

checkWord:
mov al,[esi]
cmp [esi+edi],al
jne wordIsNotAPalindrome

add esi,TYPE myWord
sub edi,TYPE myWord
loop checkWord

mov edx, offset wordIsAPalindrome
call WriteString
exit
main endp

myWord 声明:

myWord BYTE "racecar", 0

编辑:

我刚刚做了一些调整,这就是我现在的样子:

main proc
mov edi, SIZEOF myWord- TYPE myWord
mov ecx, LENGTHOF myWord/ 2
mov esi,OFFSET myWord

checkWord:
mov al, SIZEOF myWord
mov al,[esi]
cmp [myWord+edi],al
jne wordIsNotAPalindrome

add esi,TYPE myWord
sub edi,TYPE myWord
loop checkWord

mov esi, offset wordIsAPalindrome
call WriteString
call Crlf
call Crlf
exit
main endp

它现在正确地循环,当我执行 Step Over 时,它继续进行直到 wordIsAPalindrome。问题是,这是输出:

Θµ#

Press any key to continue . . .

如果您使用 IrvineWriteString,它会从 EDX 寄存器中获取字符串的偏移量,而不是 ESI,因此:

     ▼
mov edx, offset wordIsAPalindrome
call WriteString