I'm really new to low-level programming and using 16-bit with 4 registers, but i'm trying to write a program to check if a string entered from the keyboard, and terminated with a full stop (.), is a palindrome.It outputs 'y' to the vdu if it is and 'n' if not. However, im having problems it seems to only be outputting 'y',no matter if it is a palindrome or not
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
If you want to alter the program flow at some place in your code you need to use a jump:
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:
I didn't check the rest of your code, so there may be additional issues.