MIPS Assembly Language Programming
MIPS Assembly Language Programming
MIPS Assembly Language Programming
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
34 CHAPTER 2. <strong>MIPS</strong> TUTORIAL<br />
Algorithm 2.2 To determine if the string that starts at address S is a palindrome.<br />
This algorithm is appropriate for the strings that end with a newline followed by a<br />
0 character, as strings read in by the read string syscall do. (See exercise 2.10.1 to<br />
generalize this algorithm.)<br />
Note that in this algorithm, the operation of getting the character located at address<br />
X is written as ∗X.<br />
1. Let A = S.<br />
2. Let B = a pointer to the last character of S. To find the last character in S,<br />
use the following algorithm:<br />
(a) Let B = S.<br />
(b) Loop:<br />
3. Loop:<br />
• If ∗B == 0 (i.e. the character at address B is 0), then B has gone<br />
past the end of the string. Set B = B − 2 (to move B back past the<br />
0 and the newline), and continue with the next step.<br />
• Otherwise, set B = (B + 1).<br />
(a) If A ≥ B, then the string is a palindrome. Halt.<br />
(b) If ∗A �= ∗B, then the string is not a palindrome. Halt.<br />
(c) Set A = (A + 1).<br />
(d) Set B = (B − 1).