Question: USING MIPS ASSEMBLY LANGUAGE. Write an input function that will use syscall $read_string to read a string of ASCII characters from the keyboard into a

USING MIPS ASSEMBLY LANGUAGE. Write an input function that will use syscall $read_string to read a string of ASCII characters from the keyboard into a buffer, and then return the equivalent 32-bit binary integer value. If the input string can be correctly interpreted as a decimal integer, a value of zero is returned in register $v1. (The status flag) If the input string cannot be correctly interpreted, then a value of 1 is returned in register $v1. In other words, $v1 will be a flag that indicates if the input value is incorrectly specified. This algorithm consists of three phases. In the first phase, the string is scanned looking for the first digit of the number with the possibility that the Most Significant Digit may be preceded by a minus sign. The second phase involves scanning through the following string of characters, and extracting each decimal digit by subtracting out the ASCII bias. When each new decimal digit is found, multiply the current accumulated value by ten and add the most recently extracted decimal value to the accumulator. If overflow occurs while performing this arithmetic, then an error has occurred and appropriate status information should be returned. Detection of overflow must be accomplished by this function. An overflow exception must be avoided. Any invalid characters in the string would be an error condition. The second phase ends when a space is found or when a new-line character is found. At this time, it would be appropriate to take the twos complement in the accumulated value, if the number has been preceded by a minus sign. This can be accomplished by subtracting the accumulated value from zero. In the final phase, scan to the end of the buffer to verify the only remaining characters in the buffers are spaces. Write a main routine to test it.

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 Programming Questions!