Question: When you write a program in a high - level language that lets you enter a numeric value ( or use the MIPS system call

When you write a program in a high-level language that lets you enter a numeric value (or use the MIPS system call to read a number,) what you type is a string of characters. The runtime library has code to convert the characters to an actual internal binary number. Your assignment is to do that conversion, with error checking.
Write a program that does the following:
Initialize an accumulator (variable or register) to zero.
Display a prompt to the user: Enter a number:
Use the system call function to read a string into a buffer.
If the first character in your buffer is the New Line character
Go to step 9.
If the first character in your buffer is the minus sign, remember that so you can reverse the sign of the number.
Convert the number to a binary integer*, one digit at a time. If there are any characters other than decimal digits:
If it is not a New Line, show an error message and go back to step 2.
If it is a new line, continue to 7.
Add the binary number to your accumulator.
Go to step 2
Print the sum of the numbers, the total number of valid numbers entered, and the total number of errors.
Exit the program.
Write this program in MIPS assembly language using the MARS simulator.
All input is valid in the sense that you must process it and validate it. Your program must not crash.
*The process of conversion works like this: Set an accumulator to 0. Multiply your accumulator by 10, then add the new digit. You convert an ASCII digit to binary by subtracting the character 0, as we saw in class. Your program must make sure that what was entered was an actual digit, between 0 and 9, inclusive. You are done with this process when you encounter a New Line character. Consider edge cases. Is just a minus sign and no digits valid?
For example, if the user enters
12
-6
5
-52-1(Your program should mark this as an error, since it contains two minus signs.)
5-2(Error. Minus sign, if present, must be first.)
Your program would print what is shown in red below:
Error: -52-1
Error: 5-2
Sum=11(sum of 12,-6, and 5)
Count of valid numbers =3
Total number of errors: 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve the given problem using MIPS assembly language we need to write a program that will read strings of characters from the user input validate and convert them to binary numbers handle errors an... View full answer

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!