我对低级编程非常陌生并且使用带有4个寄存器的16位,但是我试图编写一个程序来检查是否从键盘输入了一个字符串,并以完整的方式终止停止(。),是一个回文。它输出' 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
答案 0 :(得分:3)
如果要在代码中的某个位置更改程序流,则需要使用跳转:
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:
我没有检查您的其余代码,因此可能还有其他问题。