Question: This exercise requires you to write an ARM program that can read a decimal integer greater than or equal to zero ( you can ignore

This exercise requires you to write an ARM program that can read a decimal integer greater than or equal to zero (you can ignore negative numbers) that the user types into the keyboard, store the result in memory, and print it out. Unfortunately, Komodo only provides a mechanism (SWI 1) to read raw ASCII characters from the input, not integers, so you will need to implement a routine to convert the sequence of ASCII characters into the integer number entered. Again, as with the exercises last week, you are only provided with a simple skeleton this time.
Your routine will need to do the following:
Print out a prompt for the user asking them to enter a number (the prompt string is provided for you labelled as enterI)
Repeatedly read characters from the keyboard and if they are digits convert it from the ASCII code returned by SWI 1 into a number. Conveniently, ASCII lays out the digits '0''9' in order with the integer codes 4857.
Note that SWI 1 does not print out the character input, so you will need to print the character out so the user can see what they typed...
Build up the integer being typed from the digits being typed (remember that each digit entered represents a power of ten entered so multiplying by 10 is your friend here...)
The number is ended when the RETURN / ENTER key is pressed (returned by SWI 1 as the ASCII code 10, that is R0 will contain the number 10).
If any other non-digit characters are entered, then this should cause an error message to be printed (on a new line), and the input is restarted by printing the prompt again (an error message is provided as errorM).
Store the integer entered into the memory location labelled value and then print it out using SWI 4. The code to print out the stored value is provided for you.
Hint: Build this up in stages, e.g. start by just reading keys until RETURN is pressed, then handle building up the integer, then add error handling etc. The order or steps is not important, but dont try to implement it all in one go.
Further Hint: Remember, 123, is one hundred plus two tens plus three, and that one hundred is 10x10, ten is just ten, units have no tens, or 1x10x10+2x10+3. I hope youve remembered your algebra classes...

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!