Hi, i need help with my code which i have been working on for a few days now! Using lc-3 assembly language i need to read in one string, check whether the string is a palindrome and display the result of the checking. I also need to echo each character typed in by the user and the input is ended with an LF character, so after the user presses the "enter" key the program should check whether the string is a palindrome or not and output the result. I've got a piece of code which displays weird things after typing in the string and pressing enter and i can't seem to find what's wrong with it.. PLEASE HELP ME FIX IT!!
.ORIG x3000
LEA R0, Message ; display a message
PUTS
LEA R1, FirstChar ; R1 points to the first
; character which will be entered
; the loop for echoing user's input and deciding whether the string is
; a palindrome
Next LD R2, LF_ASCII
GETC ; read in one character
OUT ; write character entered
ADD R3, R1, 1 ; R3 points to the next character
ADD R4, R0, R2 ; check whether the input is LF
BRnp Next ; if input is LF check whether it's,
; a palindrome, otherwise go ;back to NEXT
ADD R3, R3, -2
Check LD R3, Negate ; negate the value of the Last char
ADD R5, R1, R3 ; check whether first and last chars
; are equal
BRz NextChar ; if they are, check the next characters,
; otherwise the string isn't a palindrome
LEA R6, NotPalindrome
PUTS
BRnzp Done
Negate NOT R3, R3 ; negate R3
ADD R3, R3, 1 ; 2's complement
RET ; return
NextChar ADD R1, R1, 1 ; increment the first pointer
ADD R3, R3, -1 ; decrement the second pointer
BRp Check ; check whether the string is done
LEA R6, IsPalindrome ; the string is a palindrome
PUTS
BRnzp Done
Done HALT
Message .STRINGZ "Please enter a string: "
LF_ASCII .FILL -10
FirstChar .BLKW 10
IsPalindrome .STRINGZ "The string is a palindrome."
NotPalindrome .STRINGZ "The string is not a palindrome."
.END