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 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 into a number. Conveniently, ASCII lays out the digits in order with the integer codes
Note that SWI 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 is your friend here...
The number is ended when the RETURN ENTER key is pressed returned by SWI as the ASCII code that is R will contain the number
If any other nondigit 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 The code to print out the stored value is provided for you.
Hint: Build this up in stages, eg 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, is one hundred plus two tens plus three, and that one hundred is x ten is just ten, units have no tens, or xxx 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
