Write a MIPS assembly program that checks to see if a string is a palindrome (pa
ID: 3797902 • Letter: W
Question
Write a MIPS assembly program that checks to see if a string is a palindrome (palindrome wiki: http://en.wikipedia.org/wiki/Palindrome). The string can be stored in the static data area of your main, and is passed from main to 2 functions. The first function named string length determines the string's length. Then the string and the string length are passed to a function named palindrome, which returns a true or false indication of whether the string is a palindrome. The program should print out an indication of whether the stored string is a palindrome. Provide examples that show both cases. Allow your program to handle blanks and mixed case in the input, ignoring them, and still finding a palindrome. For example, "A daffodil slid off Ada" is an example of a palindrome if you ignore spaces and letter case. Verify it can run with MARS.Explanation / Answer
Data Segment
str1 db 'MADAM','$'
strlen1 dw $-str1
strrev db 20 dup(' ')
str_palin db 'String is Palindrome.','$'
str_not_palin db 'String is not Palindrome.','$'
Data Ends
Code Segment
Assume cs:code, ds:data
Begin:
mov ax, data
mov ds, ax
mov es, ax
mov cx, strlen1
add cx, -2
lea si, str1
lea di, strrev
add si, strlen1
add si, -2
L1:
mov al, [si]
mov [di], al
dec si
inc di
loop L1
mov al, [si]
mov [di], al
inc di
mov dl, '$'
mov [di], dl
mov cx, strlen1
Palin_Check:
lea si, str1
lea di, strrev
repe cmpsb
jne Not_Palin
Palin:
mov ah, 09h
lea dx, str_palin
int 21h
jmp Exit
Not_Palin:
mov ah, 09h
lea dx, str_not_palin
int 21h
Exit:
mov ax, 4c00h
int 21h
Code Ends
End Begin
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.