Question

Demonstrate your continuous progress in learning MIPS assembly by writing and executing the program below. Edit...

Demonstrate your continuous progress in learning MIPS assembly by writing and executing the program below. Edit the program using your favorite code editor (e.g. Notepad++) and load the programs into QtSpim for execution.

Activity Directions:

Write a program that will read a line of text and determine whether or not the text is a palindrome. A palindrome is a word or sentence that spells exactly the same thing both forward and backward. For example, the string “anna” is a palindrome, while “ann” is not. The algorithm you will be using to determine whether or not a string is a palindrome is given below.

This algorithm is appropriate for strings that end with a newline followed by a 0 character, as strings read in by the read string syscall do. Note that in this algorithm, the operation of getting the character located at address X is written as *X.

  1. Let A = S.
  2. Let B = a pointer to the last character of S. To find the last character in S, use the following algorithm:
    1. Let B = S.
    2. Loop:
      1. If *B == 0 (i.e., the character at address B is 0), then B has gone past the end of the string. Set B = B − 2 (to move B back past the 0 and the newline), and continue with the next step.
      2. Otherwise, set B = (B + 1).
  3. Loop:
    1. If A >= B, then the string is a palindrome. Halt.
    2. If *A <> 'B, then the string is not a palindrome. Halt.
    3. Set A = (A + 1).
    4. Set B = (B − 1).

Homework Answers

Answer #1

.text
main:
la $a0, string_space
li $a1, 1024
li $v0, 8
syscall
la $t1, string_space
la $t2, string_space
length_loop:
lb $t3, ($t2)
beqz$t3, end_length_loop
addu$t2, $t2, 1
b length_loop
end_length_loop:
subu$t2, $t2, 2
test_loop:
bge $t1, $t2, is_palin
lb $t3, ($t1)
lb $t4, ($t2)
bne $t3, $t4, not_palin
addu$t1, $t1, 1
subu$t2, $t2, 1
b test_loop
is_palin:
la $a0, is_palin_msg
li $v0, 4
syscall
b exit
not_palin:
la $a0, not_palin_msg
li $v0, 4
syscall
b exit
exit:
li $v0, 10
syscall
.data
string_space: .space 1024
is_palin_msg: .asciiz "The string is a palindrome.\n"
not_palin_msg: .asciiz "The string is not a palindrome.\n"

Know the answer?
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
Similar Questions
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT