Question

Write a function “check_palindrome” in MIPS which checks if an input string is a palindrome. Input...

Write a function “check_palindrome” in MIPS which checks if an input string is a palindrome. Input to the program: user inputs the string (Assume that empty strings are not allowed).Output from the program: print on console “Yes” if palindrome, and “No” if it is not a palindrome.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE SNAP-SHOT :

SAMPLE OUTPUT :

.data
buffer: .space 80
input: .asciiz "Enter string: "
output: .asciiz "Your string: "
paly: .asciiz "1" #Output for palindrome
notp: .asciiz "0" #Output for not_palindrome
.text
main:
# system call_code for print_str
li $v0, 4
# address of string to print
la $a0, input
# print the input
syscall
# code for syscall read_string
li $v0, 8
# tell syscall where the buffer is
la $a0, buffer
# tell syscall how big the buffer is
li $a1, 80
syscall
la $a0, buffer
# move buffer into a0
li $v0, 4
# print buffer
syscall
la $t1, buffer
# begining of the string
la $t2, buffer
# end of the string
li $t0, 0
loop:
lb $t3,($t2)
# load the byte of the end of the string
beqz $t3,endl
# if its equal to 0 then branch out of the loop
addu $t2, $t2,1
# if in loop the increment to next character
jal loop
# repeat the loop
upper:
addi $t4,$t4,32
j lowered
lowered:
addi $t0,$t0,1
sb $t4, 0($a0)
addi $a0,$a0,1
j loop
endl:
subu $t2, $t2, 2
# subtracting 2 to move back from \0 and \n
check:
#lb $t4, 0($a0)
#beqz $t4, after
#beq $t4, 10, after
#slti $t2, $t4, 91
#li $t3, 1
#beq $t2, $t3, upper
bge $t1, $t2, palindrome
# if both sides are equal then its a palindrome
# call palindrome
lb $t3, ($t1)
# load the byte into register t3
lb $t4, ($t2)
# load the end byte into register t4
bne $t3, $t4, notpaly
# if the two register bytes are not_equal its it not a palindrome
addu $t1, $t1, 1
# increment the beginning of the string to next char
subu $t2, $t2, 1
# decrement end of string to next char to compare
jal check # repeat the loop
palindrome:
la $a0, paly
# calling paly from data
li $v0, 4
# call_for reading string
syscall
jal exit
# jump to end
notpaly:
la $a0,notp
# calling notp from data
li $v0, 4
# call_for reading string
syscall
jal exit
# jump to end
after:
li $v0, 4
la $a0, output
syscall
la $a0, buffer
li $v0, 4
syscall
exit:
li $v0 ,10
# call to end program
syscall # call os

Add a comment
Know the answer?
Add Answer to:
Write a function “check_palindrome” in MIPS which checks if an input string is a palindrome. Input...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C Program: 6.31 (Palindromes) A palindrome is a string that's spelled the same way forward and...

    C Program: 6.31 (Palindromes) A palindrome is a string that's spelled the same way forward and backward. Some examples of palindromes are: "radar" "able was i ere i saw elba" and, if you ignore blanks: "a man a plan a canal panama" Write a recursive function testPalindrome that returns 1 if the string stored in the array is a palindrome and 0 otherwise. The function should ignore spaces and punctuation in the string. Use the function in a complete program...

  • Write a C++ program to check whether a string is a palindrome. Input a string (word)...

    Write a C++ program to check whether a string is a palindrome. Input a string (word) from the keyboard. Assume the letters are case-insenstive. Use the C++ string class. Refer to the sample output below. Sample Runs: Enter a string: otto; otto is a palindrome Enter a string: A A is a palindrome Enter a string: heooh heooh is not a palindrome

  • Write a recursive function, take a String as input, return true, if the String is a...

    Write a recursive function, take a String as input, return true, if the String is a palindrome; false otherwise. For instance, if the input is: “A nut for a jar of tuna” Then the return value is true. Notice that the non English letters are ignored; the spaces are ignored; and it is NOT case sensitive. You must write recursive function. You shall turn in a complete program, including main function to use your function to test if a String...

  • Write a python program that contains a hardcoded string and checks whether it is a palindrome...

    Write a python program that contains a hardcoded string and checks whether it is a palindrome (the same forwards as backwards). If it is then display “It is a palindrome”, otherwise display “It is not a palindrome”. A hardcoded string is simply a string defined in your program, for example: my_string = “Hello” Some sample palindromes to use are: A car, a man, a maraca Desserts, I stressed Madam, I’m Adam You will need to strip out any punctuation such...

  • Multi Part question for c++ and yes I'll rate you up thank youu! ^^ Part A:...

    Multi Part question for c++ and yes I'll rate you up thank youu! ^^ Part A: Define a struct for a Circle with a radius, circumference, area. Then define an array with 10 Circles. Input the radius for each circle from the user (and also set its circumference, area). Then output the area of the largest circle in the array. Part B : Write a function that takes as input a string from the user. Then it checks if the...

  • TASK Your task is to build a palindrome from an input string. A palindrome is a...

    TASK Your task is to build a palindrome from an input string. A palindrome is a word that reads the same backward or forward. Your code will take the first 5 characters of the user input, and create a 9- character palindrome from it. Words shorter than 5 characters will result in a runtime error when you run your code. This is acceptable for this exercise – we will cover input validation in a later class. Some examples of input...

  • 41. (10 points) EXTRA CREDIT: Write a function 'palindrome' to determine if an input string s...

    41. (10 points) EXTRA CREDIT: Write a function 'palindrome' to determine if an input string s is a palindrome. Let the empty string be (technically) Aba' is not a palindrome. You may not use the "reversed" string function, you may use either palindrome. Be case sensitive, e.g. a looping control flow to solve the problem. recursion or

  • Write a C Program that asks the user to input a string and then the user...

    Write a C Program that asks the user to input a string and then the user is prompted back whether the input string is a “Palindrome Word” or not. (A Palindrome Word reads the same backward or forward, eg. madam, racecar, etc.) Your program should contain a function that accepts the input string from the main function and returns a value indicating whether the input string is a Palindrome or not. Use Pointers to traverse the string.

  • Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward...

    Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for...

  • Write a program that uses a recursive function to determine whether a string is a character-unit...

    Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT