Write a program that checks for a palindrome. Upper and lower case are considere
ID: 3530814 • Letter: W
Question
Write a program that checks for a palindrome. Upper and lower case are considered the same. 1)System asks user to enter 80 characters and store that string in a buffer. 2) Then should call stripNonAlpha, passing starting of address of buffer via register $a0. Method stripNonAlpha should remove everything thats not a lette or deciimal digit from buffer then return starting address of the result. (For example tY7;!3 would be tY73) 3) Now it should call use toUpperCase to convert all to capitals. Should pass starting address of buffer via register $a0 4)Now should call Boolean method isAPalindrome passing starting address of the buffer returned by stripNonAlpha via $a0. Meethod isAPalindrome will return true value iff (if and only if) that buffer contains a palindrome. Then display a message saying whether or not it was a palindrome. 5) Now program asks if you want to enter another string and repeat if they say yes. If they say no it closes program.Explanation / Answer
# Joseph Meyer # Colin Zwiebel # 3 Oct 2011 # Palindrome # Recursive implimentation of Palindrome checking algorithm .data input: .asciiz "racecar" input_len: .word 7 .text main: la $a0, input_len # Load data lw $a0, 0($a0) la $a1, input jal isPalindrome # Do the Palindrome check add $a0, $v0, $zero jal printRes # Print addi $v0, $zero, 10 syscall # Exit isPalindrome: # Check base case slti $t0, $a0, 2 bne $t0, $zero, returnTrue # Make sure first and last are equal lb $t0, 0($a1) addi $t1, $a0, -1 add $t1, $t1, $a1 lb $t1, 0($t1) bne $t0, $t1, returnFalse # Shift pointer, length, recurse addi $a0, $a0, -2 addi $a1, $a1, 1 j isPalindrome returnFalse: addi $v0, $zero, 0 jr $ra returnTrue: addi $v0, $zero, 1 jr $ra # Based on this c code # int function isPanindrome(int len, char *str) # { # if (len < 2) { # return true; # } # else if (first == last) # { # return isPalindrome(len -2, str +1); # } # return false; # } .data IS_STRING: .asciiz " is" NOT_STRING: .asciiz " NOT" A_PAL_STRING: .asciiz " a PALinDROME!" .text printRes: add $t4, $a0, $zero # Stash result addi $v0, $zero, 4 la $a0, input syscall # print "<WORD>" la $a0, IS_STRING syscall # print "is" bne $t4, $zero, printResCont la $a0, NOT_STRING syscall # print "not" printResCont: la $a0, A_PAL_STRING syscall # print "a palindrome." jr $raRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.