(Solved) : Mips Assembly Language Problem Problem 2 Write Function Readint Mimics System Call 5 Non N Q37218999 . . .
Mips Assembly Language Problem
Problem 2: Write a function read_int thatmimics system call 5 (but only for non-negative integers). Thefunction needs no input parameters but should return the integergenerated by the user key presses (appropriately stored onto thestack). To read in an integer, your function should listen for andread in MMIO keyboard inputs until either (a) the user hits theenter key or (b) 10 characters have been exceeded [since thelargest possible signed 32 bit integer is 2147483647, which has 10characters]. If the user inputs an invalid character such as aletter (e.g., ‘a’) or symbol (e.g., ‘$’), your function shouldreturn -1 to indicate that an invalid number has been entered.Along the same lines, if the user tries to enter a negative number(e.g., contains ‘-‘ character) or too large of a number (i.e.,causes overflow), also have your function return -1. Lastly, if theuser types no characters at all and hits the enter key, return -1.Here are some examples that you can use as test cases:
User Types: 1 2 3 4ENTER Return: 1234
User Types: 0ENTER Return: 0
User Types: 5 3 g 9 4ENTER Return: -1 #invalid character ‘g’
User Types: – 3 8ENTER Return:-1 # invalid character ‘-‘
User Types: 9 7 3 5 9 1 8 3 58 Return:-1 # overflow
User Types: 1 2 3 4 5 6 7 8 90 Return: 1234567890 # notoverflow
User Types:ENTER Return:-1 # user did not enter any digits
Hint: You will need to refer to an ASCII table to figure outmappings between digit characters’ ASCII values and theircorresponding numeric values. You will also need this table todetermine which characters are invalid. You can find an ASCII tablein the back of the textbook or you can simply Google it.
Expert Answer
Answer to Mips Assembly Language Problem Problem 2: Write a function read_int that mimics system call 5 (but only for non-negative…
OR