检查回文的 Asm 程序

Asm program to check for a palindrome

我真的不熟悉低级编程,使用 16 位和 4 个寄存器,但我正在尝试编写一个程序来检查从键盘输入的字符串是否以句号终止( .), 如果是 palindrome.It 输出 'y' 到 vdu,如果不是则输出 'n'。 但是,我有问题它似乎只输出'y',不管它是否是回文

mov bl,70        ; Memory Start Address
mov dl,0         ; how many characters make up the string

loop:
in 00            ;read input from the keyboard
cmp al, 2E       ;check to see if the input is a fullstop
jz palin         ;jump to see if the input is a palindrome
mov [bl], al     ;save the input in memory address
inc bl           ;goto next memory addr in bl
inc dl           ;increment dl by 1 to the length of the string
push al
jmp loop

palin:
cmp dl,0         ;check if it has gone through the whole string
jz ispalin       ;jump it has then the string is a palindrome
mov bl, 70       ;bring back the first input character
mov dl,[bl]
pop cl           ;put the last input character
cmp cl,dl        ;check if these two values are the same
jnz notpalin     ;if they are not then jump to notpalin
inc bl           ;go to the next input addr
dec dl           ;take away 1 from the length of the string
jmp palin        ;jump pack to the start of palin

notpalin:
mov dl,c0
mov cl,6E
mov [dl],cl      ;print the character 'n' to the vdu

ispalin:
mov dl,c0
mov cl,79
mov [dl],cl      ;print the character 'y' to the vdu

end

如果您想在代码中的某个地方更改程序流程,您需要使用跳转:

notpalin:
mov dl,c0
mov cl,6E
mov [dl],cl      ;print the character 'n' to the vdu
jmp done         ; do not execute the code at ispalin

ispalin:
mov dl,c0
mov cl,79
mov [dl],cl      ;print the character 'y' to the vdu

done:

我没有检查您的其余代码,因此可能还有其他问题。