Question: You are required to write a MIPS program that prompts a user for a line of characters (only decimal digits or whitespace characters) and reads

You are required to write a MIPS program that prompts a user for a line of characters (only decimal digits or whitespace characters) and reads the line typed by the user. If the line contains just whitespace characters your program should simply output the message Line contains only whitespace characters. and stop. Otherwise, your program should compute and output the following:

1.The total number of decimal integers in the string.

2.Value of the maximum decimal integer in the string.

3.The maximum number of 1's in the binary representations of the integers in the string.

4.All given integers with the maximum number of 1's in the binary representations. The integers should be printed in order as they appear in the input line.

Example:

Suppose the user types:

12 346 31 44 73

Then (you do not need a code for this table),

Integers Binary Representation Number of 1's
12 1100 2
346 101011010 5
31 11111 5
44 101100 3
73 1001001 3

So, for this example the program will print these answers:

1.The number of the given integer is 5.

2.The maximum value of the given integers is 346.

3.The maximum number of 1's in the binary representations of the given integers is 5.

4.The given integers that have four 1's in the binary representations are 346 and 31.

Program outline: The outline for your program must be the following.

1. Prompt the user for a line of characters.

2. Read the line of characters typed by the user.

3. If the line has only whitespace characters print the message: "Line contains only white space characters." and stop.

Otherwise compute the quantities mentioned above and print the answers.

4. Stop.

Suggestions:

1. Each time your program is executed, it should handle line of characters.

2. Any line typed by a user has at most 80 characters including the newline character.

3. End of any line is determined by the character.

4. You may assume that the character typed by the user are decimal digits or whitespace character. A whitespace character refers to a space, a tab or the newline character.

5. It is excepted to check whether the input line consists of just whitespace characters, no other error checks are needed.

6. There is no need to convert the integer to binary; when the integer is in the register, it is already in binary form.

7. Use bitwise operations to count the number of 1s.

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!