Write an assembly program called hw5_ex1, stored in file hw5_ex1.asm. This program should prompt the user to enter 10 numbers between 0 and 9 (both included). The program should print an error message and re-prompt the user for another number if the number entered is invalid. These numbers should be stored in memory as 1-byte values. Once the user has entered 10 valid numbers, the program should just print them out in the order they were entered.
Here is an example interaction with the program (note that in the end only the 10 valid entered numbers are taken into account):
% ./hw5_ex1
Enter a number between 0 and 9: 2
Enter a number between 0 and 9: 12
Invalid number!
Enter a number between 0 and 9: 3
Enter a number between 0 and 9: 1
Enter a number between 0 and 9: 0
Enter a number between 0 and 9: 2
Enter a number between 0 and 9: 2
Enter a number between 0 and 9: -12
Invalid number!
Enter a number between 0 and 9: 3
Enter a number between 0 and 9: 4
Enter a number between 0 and 9: 5
Enter a number between 0 and 9: 1
2
3
1
0
2
2
3
4
5
1
You can assume that the user always enters a number (and not random input).
Exercise #2: Histogram - step 2 [30pts]
Extend the program from the previous question so that it computes a tally for each possible number. For instance, if the user has entered the number "3" 4 times, then the tally for number "3" is 4. Instead of merely printing the entered number like in the previous question, the program should print the tallies in order, with an appropriately readable format.
Here is an example interaction with the program:
% ./hw5_ex2Since number "0" was never entered, its tally is 0; since number "1" was entered twice, its tally is 2; etc.
Enter a number between 0 and 9: 1
Enter a number between 0 and 9: 1
Enter a number between 0 and 9: 3
Enter a number between 0 and 9: 45
Invalid number!
Enter a number between 0 and 9: 2
Enter a number between 0 and 9: 3
Enter a number between 0 and 9: 3
Enter a number between 0 and 9: 3
Enter a number between 0 and 9: 7
Enter a number between 0 and 9: 8
Enter a number between 0 and 9: 9
The tally for 0 is: 0
The tally for 1 is: 2
The tally for 2 is: 1
The tally for 3 is: 4
The tally for 4 is: 0
The tally for 5 is: 0
The tally for 6 is: 0
The tally for 7 is: 1
The tally for 8 is: 1
The tally for 9 is: 1
Exercise #3: Histogram - step 3 [ 10pts EXTRA CREDIT ]
Modify your program from the previous section so that instead of printing tallies the program prints a (crude) histogram of the numbers. Namely, the x-axis lists the possible numbers from 0 to 9, and bars are shown above each number to represent the tally (with the maximum bar height being 10, and the minimum bar being 0).
Of course, since we don't have access to graphics at this point, we have to "fake" it with ASCII characters. Here is an example interaction with the program:
./hw5_ex3
Enter a number between 0 and 9: 1
Enter a number between 0 and 9: 1
Enter a number between 0 and 9: 3
Enter a number between 0 and 9: 4
Enter a number between 0 and 9: 0
Enter a number between 0 and 9: 1
Enter a number between 0 and 9: 9
Enter a number between 0 and 9: 9
Enter a number between 0 and 9: 9
Enter a number between 0 and 9: 9
#
# #
# #
## ## #
----------
0123456789
In the above histogram, the bar above number 4 is only of height 1 because number 4 was entered only once; the bar above number 9 is of height 4 because number 9 was entered 4 times; there is no bar above number 7 because number 7 was never entered.