Question: 5. Program Description: You are to write a program that does the following: -Analyzes a string of small (non-capital) letters in memory and puts them

5. Program Description: You are to write a program that does the following:

-Analyzes a string of small (non-capital) letters in memory and puts them in alphabetical order. (The sequence could be of most any length up to a line, but for consistency, make the string 12-15 random small letters. The sequence should be labeled string 1 in the data statements, followed by a .space directive to reserve at least 20-30 characters (this is extra room in case you input a few extra characters, so that you will still have a null-terminated string, since .space clears all byte spaces to 0).

-Inputs the string from the keyboard using a syscall 8. They should be placed in the reserved space labeled string 1.

-Alphabetizes the string using a loop and outputs the alphabetized string to the simulated console.

-Assures all characters in the set are really small letters not capitals, punctuation, numbers, etc. If a character is incorrect, it should be deleted from the alphabetized list.

-The output of ordered letters is preceded by a statement: The alphabetized string is:

6 . Comments About Program and Hint: This is an example of a program which can be done with a recursive loop, such as those demonstrated in class. However, in this case, there is a somewhat easier approach that you can use. Simply start by comparing the characters all to a and if there are any as, store them in a new string (labeled string 2). Then compare to b, c, etc. Such a loop will also let you start out each comparison by making sure that the character is a-z. If not, throw it away and do the next compare. When you get to a 0, stop, since your .space command has assured that the string is null-terminated. Although you have to go through the entire loop 26 times (a-z), the computer loop is so fast that this is really not a problem. If you really wish to do a sort/compare such as in the homework problem noted above (in which you only go through the string of letters once, but you go back-and-forth in the string a great deal!), you are welcome to do so, but the approach described above is easier to implement.

* write the program on notepad and run it on spim, give the program on the section box with instruction thanks you!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!