Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
ok please fix this errors that this program is having. the main issue its counding non - palindromes as palindromes here is the current code
ok please fix this errors that this program is having. the main issue its counding nonpalindromes as palindromes here is the current code that i have for this program, please give me the completed subroutines or the whole program. Note: Please make sure the palindrome subroutine is using recursion, IT MUST USE RECURSION! thanks: attached is the palindrome subroutine pdf to fix ORIG xORIG palindrome ADD R R # ; Backup ; Initialize stack LD R stackaddr ; Call main subroutine LEA R main JSRR R ; Halt the program HALT ; ; Main Subroutine ; main ; Call subroutine to get user input LEA R userprompt PUTS LEA R userstring JSR getuserstring ; Call subroutine to calculate string length LEA R userstring JSR strlen ; Call recursive palindrome subroutine LEA R userstring ADD R R R ; Calculate the address of the last character ADD R R # JSR palindrome ; Check if the result is true and print appropriate message ADD R R # BRz notpalindrome LEA R resultstring PUTS ; Print The string is LEA R finalstring PUTS ; Print a palindrome BR endprogram notpalindrome LEA R resultstring PUTS ; Print The string is LEA R notstring PUTS ; Print not LEA R finalstring PUTS ; Print a palindrome endprogram HALT ; ; Required labelsaddresses ; ; Stack address DO NOT CHANGE stackaddr FILL xFE ; Addresses of subroutines, other than main getuserstringaddr FILL x strlenaddr FILL x palindromeaddr FILL x ; Reserve memory for strings in the progrtam userprompt STRINGZ "Enter a string: resultstring STRINGZ "The string is notstring STRINGZ "not finalstring STRINGZ "a palindrome ; Reserve memory for user input string userstring BLKW END ; ; getuserstring ; ; Description: Prompts the user for a string and stores it at a specified memory address. ; Input: R Address of the user prompt string. ; R Address where the user string should be stored. ; Output: None. ; ORIG x getuserstring ADD R R # ; Backup R STR R R # ADD R R # ; Backup R STR R R # ADD R R # ; Backup R STR R R # ; Loop to get user input getcharloop GETC ; Get user input OUT ; Echo the character ADD R R # ; Copy input character to R ADD R R # ; Check if Enter key newline ASCII xA is pressed BRz endinput ; If Enter key is pressed, end input STR R R # ; Store character in memory ADD R R # ; Move to next memory location BR getcharloop ; Repeat the loop to get next character endinput AND R R # ; Set R to zero zero terminator STR R R # ; Append zero terminator to string LDR R R # ; Restore R ADD R R # LDR R R # ; Restore R ADD R R # LDR R R # ; Restore R ADD R R # RET END ; ; strlen ; ; Description: Computes the length of a zeroterminated string. ; Input: R Address of the zeroterminated string. ; Output: R Length of the string number of nonzero characters ; ORIG x strlen ADD R R # ; BackupR STR R R # ADD R R # ; Backup R STR R R # ADD R R # ; Backup R STR R R # AND R R # ; Initialize length counter LD R negnewlinesub iterate LDR R R # ; Load character ADD R R R ; Move to the next character BRz enditerate ; Check if null terminator is reached ADD R R # ; Increment length counter ADD R R # BR iterate enditerate LDR R R # ; Restore R ADD R R # LDR R R # ; Restore R
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started
ok please fix this errors that this program is having.
the main issue its counding nonpalindromes as palindromes
here is the current code that i have for this program, please give me the completed subroutines or the whole program.
Note: Please make sure the palindrome subroutine is using recursion, IT MUST USE RECURSION!
thanks: attached is the palindrome subroutine pdf to fix
ORIG xORIG
palindrome
ADD R R # ; Backup
; Initialize stack
LD R stackaddr
; Call main subroutine
LEA R main
JSRR R
; Halt the program
HALT
;
; Main Subroutine
;
main
; Call subroutine to get user input
LEA R userprompt
PUTS
LEA R userstring
JSR getuserstring
; Call subroutine to calculate string length
LEA R userstring
JSR strlen
; Call recursive palindrome subroutine
LEA R userstring
ADD R R R ; Calculate the address of the last character
ADD R R #
JSR palindrome
; Check if the result is true and print appropriate message
ADD R R #
BRz notpalindrome
LEA R resultstring
PUTS ; Print The string is
LEA R finalstring
PUTS ; Print a palindrome
BR endprogram
notpalindrome
LEA R resultstring
PUTS ; Print The string is
LEA R notstring
PUTS ; Print not
LEA R finalstring
PUTS ; Print a palindrome
endprogram
HALT
;
; Required labelsaddresses
;
; Stack address DO NOT CHANGE
stackaddr FILL xFE
; Addresses of subroutines, other than main
getuserstringaddr FILL x
strlenaddr FILL x
palindromeaddr FILL x
; Reserve memory for strings in the progrtam
userprompt STRINGZ "Enter a string:
resultstring STRINGZ "The string is
notstring STRINGZ "not
finalstring STRINGZ "a palindrome
; Reserve memory for user input string
userstring BLKW
END
;
; getuserstring
;
; Description: Prompts the user for a string and stores it at a specified memory address.
; Input: R Address of the user prompt string.
; R Address where the user string should be stored.
; Output: None.
;
ORIG x
getuserstring
ADD R R # ; Backup R
STR R R #
ADD R R # ; Backup R
STR R R #
ADD R R # ; Backup R
STR R R #
; Loop to get user input
getcharloop
GETC ; Get user input
OUT ; Echo the character
ADD R R # ; Copy input character to R
ADD R R # ; Check if Enter key newline ASCII xA is pressed
BRz endinput ; If Enter key is pressed, end input
STR R R # ; Store character in memory
ADD R R # ; Move to next memory location
BR getcharloop ; Repeat the loop to get next character
endinput
AND R R # ; Set R to zero zero terminator
STR R R # ; Append zero terminator to string
LDR R R # ; Restore R
ADD R R #
LDR R R # ; Restore R
ADD R R #
LDR R R # ; Restore R
ADD R R #
RET
END
;
; strlen
;
; Description: Computes the length of a zeroterminated string.
; Input: R Address of the zeroterminated string.
; Output: R Length of the string number of nonzero characters
;
ORIG x
strlen
ADD R R # ; BackupR
STR R R #
ADD R R # ; Backup R
STR R R #
ADD R R # ; Backup R
STR R R #
AND R R # ; Initialize length counter
LD R negnewlinesub
iterate
LDR R R # ; Load character
ADD R R R ; Move to the next character
BRz enditerate ; Check if null terminator is reached
ADD R R # ; Increment length counter
ADD R R #
BR iterate
enditerate
LDR R R # ; Restore R
ADD R R #
LDR R R # ; Restore R
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started