Question: In this question you are asked to complete the MIPS code below to implement a subroutine which tests whether or not an input string is

In this question you are asked to complete the MIPS code below to implement a subroutine which tests whether or not an input string is a palindrome. A palindrome is a string which reads the same way when read backwards and forwards. For example, the string 12forof21 is a palindrome.

In this question you are asked to complete the MIPS code below

In this question you are asked to complete the MIPS code below to implement a subrou- tine which tests whether or not an input string is a palindrome. A palindrome is a string which reads the same way when read backwards and forwards. For example, the string "12fo- rof21" is a palindrome. The string you are asked to test has an associated label "string". The NULL termination character should not be considered for the palindrome test, but your code should work for any such test string. For all your working your use of registers should conform to the conventions introduced in class. Be sure to comment your code carefully. Note that the "main" routine is already written. Proceed as follows: a) Assume a subroutine called "length" has already been written for you. b) Complete the subroutine "palind which takes as input two arguments, the first being a pointer to the first element in a string and the second being the length of the string. This routine should return a value of 1 if the test string is a palindrome and 0 otherwise. Do not use recursion for this part.[20 marks] c) Come up with an entirely new version of the subroutine palind which is recursive. To do so you need to first come up with the proper recursive step. Hint: A string having one element is a palindrome. A string having two elements is a palindrome if... A string having 3 elements is a palindrome if..., and so on.[20 marks) Your program begins here. .data asciiz CabbulafadodafalUbbac'' # this is the test string string: .text .align 2 .globl main length: # first line of length' subroutine jr $ra # last line of length's palind: # first line of palind'' subroutine jr $ra main: la $al, string jal length add $a1, $v0, $zero la $a0, string jal palind nop # 'main'' program begins by getting pointer # to the string and calling length' # now set up the arguments for "palind' and # call it # last line of "main'" In this question you are asked to complete the MIPS code below to implement a subrou- tine which tests whether or not an input string is a palindrome. A palindrome is a string which reads the same way when read backwards and forwards. For example, the string "12fo- rof21" is a palindrome. The string you are asked to test has an associated label "string". The NULL termination character should not be considered for the palindrome test, but your code should work for any such test string. For all your working your use of registers should conform to the conventions introduced in class. Be sure to comment your code carefully. Note that the "main" routine is already written. Proceed as follows: a) Assume a subroutine called "length" has already been written for you. b) Complete the subroutine "palind which takes as input two arguments, the first being a pointer to the first element in a string and the second being the length of the string. This routine should return a value of 1 if the test string is a palindrome and 0 otherwise. Do not use recursion for this part.[20 marks] c) Come up with an entirely new version of the subroutine palind which is recursive. To do so you need to first come up with the proper recursive step. Hint: A string having one element is a palindrome. A string having two elements is a palindrome if... A string having 3 elements is a palindrome if..., and so on.[20 marks) Your program begins here. .data asciiz CabbulafadodafalUbbac'' # this is the test string string: .text .align 2 .globl main length: # first line of length' subroutine jr $ra # last line of length's palind: # first line of palind'' subroutine jr $ra main: la $al, string jal length add $a1, $v0, $zero la $a0, string jal palind nop # 'main'' program begins by getting pointer # to the string and calling length' # now set up the arguments for "palind' and # call it # last line of "main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!