Write a MIPS program that will read in a base (as an integer) and a value (nonne
ID: 3803183 • Letter: W
Question
Write a MIPS program that will read in a base (as an integer) and a value (nonnegative integer but as an ASCII string) in that base and print out the decimal value; you must implement a function (which accepts a base and an address for a string as parameters, and returns the value) and call the function from the main program. The base will be given in decimal and will be between 2 and 36, and the digits for the values will be in set [0…9, a…z]. You can assume that no overflow will occur and the value is valid in the given base.
An example run will be:
Enter a base (between 2 and 36 in decimal): 2
Enter a number in base 2: 101
The value in decimal is: 5
Then you need to test program using three different cases (you must use three different bases).
Explanation / Answer
There are no negative ASCII values. ASCII includes definitions for 128 characters. Their indexes are all positive.char type being a signed integer type, and int being a wider signed integer type, and thus the character constant is considered a negative number and is sign-extended to the wider integer type.The C standard allows for compiler implementations to choose whether they consider char to be signed or unsigned. Some compilers even have compile time switches to change the default.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.