Assignment 2
CS2340.005 Spring 2022
Number Conversion
Write a program that does the following:
1. Initialize an accumulator (variable or register) to zero.
2. Display a prompt to the user: “Enter a number: “
3. Use the system call function to read a string into a buffer.
4. If the first character in your buffer is the New Line character
A. Go to step 9.
5. If the first character in your buffer is the minus sign, remember that so you can reverse the sign of the number.
6. Convert the number to a binary integer*, one digit at a time. If there are any characters other than decimal digits:
A. If it is not a New Line, show an error message and go back to step 2.
B. If it is a new line, go to 7.
7. Add the number to your accumulator.
8. Go to step 2
9. Print the sum of the numbers and the average.
10. 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: 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.
To hand in through eLearning: A Zip file named CS2340-Asg2-
Grading Criteria |
|
Comments and variable names |
15 |
Correctly outputs the sum and count |
60 |
Does not crash |
25 |
Total |
100 |