Write a program that accepts a string from the user. You can assume the length of the string will be less than 30 characters and only lower case letters are entered.
Your program should then display the string in sorted order and determine if the string entered is a palindrome. (A palindrome is a string that is the same whether read from left to right or right to left, e.g. racecar). You can ignore spaces for sorting and determining if it is a palindrome. Afterwards, ask the user if they want to enter in another string. If so, repeat the process, else quit the program.
Here is an example:
Please enter in a string of a maximum of 30 lower case letters: i love assembly language
The sorted string is: aaabeeeggilllmnossuvy
The string is not a palindrome
Would you like to enter in another string (y/n)? n
Good bye.
here is my attemp
.section ".data"
/*Variables*/
input: .word 0
yesNo: .byte 0
nl: .asciz "\n"
prompt1: .asciz "\nPlease enter in a string of a maximum of 30 lower case letter:"
prompt2: .asciz "\nWould you like to enter in a nnother string(y/n)?:"
format1: .asciz "%d%c"
format2: .asciz "%c%c"
format3: .asciz "\nThe sorted string is:"
format4: .asciz "\nThe strin is a palindrom:"
format5: .asciz "\nThe strin is not a palindrom:"
format6: .asciz "\nGood bye:"
format7: .asciz "%d"
.align 8
.global main
.section ".text"
var(string,1,30*1)
var(reverse,1,30*1)
var(num,4)
define(letter, l0)
define(iter, l1)
define(total, l2)
define(rev_indx, l3)
define(str_index, l4)
main:
save %sp, -96, %sp
repeat:
set prompt1, %o0 !ask fo a number
call printf
nop
set format2, %o0 !input needs
set input, %o1 !address where input is stored
call scanf
nop
set input, %o1
ldub [%fp+num], %total
clr %str_index
clr %iter
loop:
stb %o0, [%fp +string +%iter]
add %o0, 1, %o0
add %iter, 1, %%iter
cmp %iter, %total
bl loop
nop
ld [fp + num], %total
clr %rev_index
mov %total, %str_index
sub %str_index, 1, %str_index
loop1:
ldub [%fp + string +%str_index], %o0
stb %o0, [%fp + reverse +%rev_index]
add %rev_iindex,1 , %rev_index
sub %str_index,1 , %str_index
cmp %rev_index , 1 ,%total
bl loop
nop
set prompt2, %o0
call printf
nop
set format2, %o0 !getting a character and a newline
set yesNo, %o1
set nl, %o2
call scanf
nop
set yesNo, %l0
ldub [%l0], %o0 !get the ys/no from memory
cmp %o0, 'y'
be repeat
nop !yes then try again
ret !get out
restore