Write a program that accepts astring from the user. You can assume the length of
ID: 3615343 • Letter: W
Question
Write a program that accepts astring from the user. You can assume the length of the string willbe less than 30 characters and only lower case letters areentered.
Your program should then displaythe string in sorted order and determine if the string entered is apalindrome. (A palindrome is a string that is the same whether readfrom left to right or right to left, e.g. racecar). Youcan ignore spaces for sorting and determining if it is apalindrome. Afterwards, ask the user if they want to enter inanother string. If so, repeat the process, else quit theprogram.
Here is an example:
Please enter in a string of a maximum of 30 lower caseletters: 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
Explanation / Answer
Here is my attempt it is not finished any help plz .section ".data" /*Variables*/ input: .word 0 yesNo: .byte 0 nl: .asciz " " prompt1: .asciz " Please enter in a string of a maximum of 30lower case letter:" prompt2: .asciz " Would you like to enter in a nnotherstring(y/n)?:" format1: .asciz "%d%c" format2: .asciz "%c%c" format3: .asciz " The sorted string is:" format4: .asciz " The strin is a palindrom:" format5: .asciz " The strin is not a palindrom:" format6: .asciz " Good 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 !getting the array 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 ! getting the revers array 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 !code go here set prompt2, %o0 call printf nop set format2,%o0 !getting a character and anewline set yesNo, %o1 set nl, %o2 call scanf nop set yesNo, %l0 ldub [%l0],%o0 !get the ys/no frommemory cmp %o0, 'y' be repeat nop !yes then try again ret !getout restore
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.