Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can you complete this exercise for me , my code does not allow me to use back space in the console: code: ; Program initialization
can you complete this exercise for me my code does not allow me to use back space in the console:
code:
; Program initialization and stack setup
ORIG x
ld r topstackaddr ; Load the top of the stack address into R
; Load addresses and call subroutines
ld r arrayptr ; Load the address of the array to store the input string.
ld r getstring ; Load the address of the subroutine to get the input string.
jsrr r ; Jump to the subroutine and save the return address.
ld r ispalindrome ; Load the address of the palindrome checking subroutine.
jsrr r ; Jump to the palindrome checking subroutine.
; Output the result to the console
printpalindrome:
lea r string ; Load the address of the introductory string.
puts ; Print the introductory string.
lea r startquote ; Load the address of the opening quote.
puts ; Print the opening quote.
ld r arrayptr ; Load the address of the input string.
puts ; Print the input string.
lea r endquote ; Load the address of the closing quote.
puts ; Print the closing quote.
add r r # ; Set condition codes based on Rs value.
brz printisnotpalindrome ; Branch if the string is not a palindrome.
printisapalindrome:
lea r isapalindrome ; Load the address of the palindrome confirmation message.
puts ; Print the palindrome confirmation.
br endprintpalindrome ; Branch to the end of printing.
printisnotpalindrome:
lea r isnotpalindrome ; Load the address of the nonpalindrome message.
puts ; Print the nonpalindrome message.
endprintpalindrome:
halt ; Halt the program.
; Data storage
getstringfill x ; Address of the get string subroutine.
ispalindromefill x ; Address of the palindrome checking subroutine.
arrayptr fill x ; Address of the array to store the input string.
string stringz "The string ; Introductory text for output.
startquote stringz ; Opening quote for the string.
endquote stringz ; Closing quote for the string.
isapalindrome stringz IS a palindrome.
; Palindrome confirmation message.
isnotpalindrome stringz IS NOT a palindrome.
; Nonpalindrome message.
topstackaddr fill xFE ; Top of the stack address.
END
;
; Subroutine: SUBGETSTRING
; This subroutine prompts the user to input a string and stores it in an array.
; The input is terminated by the ENTER key, and the string is nullterminated.
;
ORIG x
add r r #
str r r # ; Store R on the stack.
add r r #
str r r # ; Store R on the stack.
ld r sentinel ; Load the ASCII value for Enter.
not r r ; Prepare to check for Enter key.
add r r #
and r r # ; Clear R to count characters.
lea r prompt ; Load the address of the prompt message.
puts ; Display the prompt.
dowhileloop:
getc ; Get a character from the user.
out ; Echo the character.
str r r # ; Store the character in the array.
ldr r r # ; Load the stored character for comparison.
add r r r ; Check if the character is Enter.
brz enddowhileloop ; Exit loop if Enter is pressed.
add r r # ; Increment character count.
add r r # ; Increment address pointer.
brnp dowhileloop ; Continue if not Enter.
enddowhileloop:
ld r zerosentinel
str r r # ; Store null terminator.
ldr r r # ; Restore R
add r r #
ldr r r # ; Restore R
add r r #
ret ; Return from subroutine.
sentinel FILL xA ; ASCII value for Enter.
prompt STRINGZ "Please input a string of text, press ENTER to finalize your input:
zerosentinel FILL x
END
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started