Question: this is my code, i have errors, can you change it: . orig x 3 0 0 0 ; Initialize the stack pointer. Don't worry
this is my code, i have errors, can you change it: orig x
; Initialize the stack pointer. Don't worry about what that means for now.
ld r stackstartaddr ; DO NOT MODIFY, AND DON'T USE R OTHER THAN FOR BACKUPRESTORE
; call start subroutine
lea r start
jsrr r
;
; Start Subroutine
;
start
ld r inputarray
ld r getinputstring
jsrr r
ld r converttoupper
jsrr r
ld r checkpalindrome
jsrr r
ld r inputarray
ld r negativeone
not r r
add r r #
STARTLOOP
add r r r
brn NOTPALINDROME
lea r successmsg
PUTS
lea r successmsgend
PUTS
br EXITPROGRAM
NOTPALINDROME
lea r failuremsg
PUTS
lea r failuremsgend
PUTS
EXITPROGRAM
halt
; your local data goes here
getinputstring FILL x
checkpalindrome FILL x
converttoupper FILL x
stackstartaddr FILL xFE ; DO NOT MODIFY THIS LINE OF CODE
inputarray FILL x
negativeone FILL #
successmsg STRINGZ "The string"
successmsgend STRINGZ is a palindrome
failuremsg STRINGZ "The string"
failuremsgend STRINGZ is not a palindrome
end
; your subroutines go below here
;
; Subroutine: GETINPUTSTRING
; Parameter R: The starting address of the character array
; Postcondition: The subroutine has prompted the user to input a string,
; terminated by the ENTER key the "sentinel" and has stored
; the received characters in an array of characters starting at R
; the array is NULLterminated; the sentinel character is NOT stored.
; Return Value R: The number of nonsentinel chars read from the user.
; R contains the starting address of the array unchanged.
;
ORIG x
add r r #
str r r #
add R R #
str R R #
add R R #
str R R #
add R R #
str R R #
ld r enterkey
not r r
add r r #
lea r promptmsg
puts
and r r #
add r r xA
and r r #
READLOOP
and r r #
GETC
OUT
add r r r
BRz ENDINPUT
str r r #
add r r #
add r r #
BR READLOOP
ENDINPUT
ldr r r #
add R R #
ldr r r #
add R R #
ldr r r #
add R R #
ldr r r #
add R R #
ret
;data
promptmsg STRINGZ "Enter a string:
enterkey FILL #
end
;
; Subroutine: CHECKPALINDROME
; Parameter R: The starting address of a nullterminated string
; Parameter R: The number of characters in the array.
; Postcondition: The subroutine has determined whether the string at R
; is a palindrome or not, and returns a flag to that effect.
; Return Value: R if the string is a palindrome, otherwise
;
orig x
ld r flagtrue
add r r #
add r r #
add r r r
CHECKLOOP
add r r #
str r r #
add R R #
str R R #
add R R #
str R R #
add R R #
str R R #
ldr r r #
ldr r r #
not r r
add r r #
add r r #
add r r #
add r r r
brz SKIPCOMPARE
ld r flagfalse
SKIPCOMPARE
add r r #
brnz ENDCHECK
jsr CHECKLOOP
ENDCHECK
ldr r r #
add R R #
ldr r r #
add R R #
ldr r r #
add R R #
ldr r r #
add R R #
ret
flagfalse FILL #
flagtrue FILL #
palindromeaddress FILL x
end
;
; Subroutine: CONVERTTOUPPER
; Parameter R: Starting address of a nullterminated string
; Postcondition: The subroutine has converted the string to uppercase
; inplace ie the uppercase string has replaced the original string
; No return value, no output, but R still contains the array address, unchanged
;
