Answered step by step
Verified Expert Solution
Link Copied!

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 x3000
ld r6, top_stack_addr ; Load the top of the stack address into R6.
; Load addresses and call subroutines
ld r1, array_ptr ; Load the address of the array to store the input string.
ld r2, get_string_3200 ; Load the address of the subroutine to get the input string.
jsrr r2 ; Jump to the subroutine and save the return address.
ld r2, is_palindrome_3400 ; Load the address of the palindrome checking subroutine.
jsrr r2 ; Jump to the palindrome checking subroutine.
; Output the result to the console
print_palindrome:
lea r0, string ; Load the address of the introductory string.
puts ; Print the introductory string.
lea r0, start_quote ; Load the address of the opening quote.
puts ; Print the opening quote.
ld r0, array_ptr ; Load the address of the input string.
puts ; Print the input string.
lea r0, end_quote ; Load the address of the closing quote.
puts ; Print the closing quote.
add r4, r4, #0 ; Set condition codes based on R4's value.
brz print_is_not_palindrome ; Branch if the string is not a palindrome.
print_is_a_palindrome:
lea r0, is_a_palindrome ; Load the address of the palindrome confirmation message.
puts ; Print the palindrome confirmation.
br end_print_palindrome ; Branch to the end of printing.
print_is_not_palindrome:
lea r0, is_not_palindrome ; Load the address of the non-palindrome message.
puts ; Print the non-palindrome message.
end_print_palindrome:
halt ; Halt the program.
; Data storage
get_string_3200.fill x3200 ; Address of the get string subroutine.
is_palindrome_3400.fill x3400 ; Address of the palindrome checking subroutine.
array_ptr .fill x4000 ; Address of the array to store the input string.
string .stringz "The string " ; Introductory text for output.
start_quote .stringz "\"\"" ; Opening quote for the string.
end_quote .stringz "\"\"" ; Closing quote for the string.
is_a_palindrome .stringz " IS a palindrome.
" ; Palindrome confirmation message.
is_not_palindrome .stringz " IS NOT a palindrome.
" ; Non-palindrome message.
top_stack_addr .fill xFE00 ; Top of the stack address.
.END
;------------------------------------------------------------------------
; Subroutine: SUB_GET_STRING_3200
; 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 null-terminated.
;------------------------------------------------------------------------
.ORIG x3200
add r6, r6, #-1
str r7, r6, #0 ; Store R7 on the stack.
add r6, r6, #-1
str r1, r6, #0 ; Store R1 on the stack.
ld r2, sentinel ; Load the ASCII value for Enter.
not r2, r2 ; Prepare to check for Enter key.
add r2, r2, #1
and r5, r5, #0 ; Clear R5 to count characters.
lea r0, prompt ; Load the address of the prompt message.
puts ; Display the prompt.
do_while_loop:
getc ; Get a character from the user.
out ; Echo the character.
str r0, r1, #0 ; Store the character in the array.
ldr r3, r1, #0 ; Load the stored character for comparison.
add r3, r3, r2 ; Check if the character is Enter.
brz end_do_while_loop ; Exit loop if Enter is pressed.
add r5, r5, #1 ; Increment character count.
add r1, r1, #1 ; Increment address pointer.
brnp do_while_loop ; Continue if not Enter.
end_do_while_loop:
ld r0, zero_sentinel
str r0, r1, #0 ; Store null terminator.
ldr r1, r6, #0 ; Restore R1.
add r6, r6, #1
ldr r7, r6, #0 ; Restore R7.
add r6, r6, #1
ret ; Return from subroutine.
sentinel .FILL x0A ; ASCII value for Enter.
prompt .STRINGZ "Please input a string of text, press [ENTER] to finalize your input: "
zero_sentinel .FILL x0
.END
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

Explain the pages in white the expert taxes

Answered: 1 week ago