Some notes on the final:
Problem 9 asks you to write a procedure that will read in a decimal number of upto 8 digits. Your procedure should store the number in AX. All other registers should be unmodified by the procedure.
How do you do this? Let's start with an example, and work out the solution in Java-like pseudocode. If the user entered 1345, you would have to read in each character, and then reconstruct the number from those digits. Remember that digits are stored as ASCII codes, and that the codes are 30h off from the number they store. For example, the ASCII code for '1' is 31h, '2' is 32h, '3' is 33h, etc. So, after reading in a character, subtracting 30h gives the desired number.
For our example, we would read in the first number, subtract 30h, and add it to a running total (so, the total would 1). If we then add the next number (minus the 30h), we would have 4. Instead, if you think about building the number up from left to right, we would want 13. To get this in general, we would take the running total, multiply it by 10, and add the new number. Repeating this at each step will build up the desired number. Writing this in pseudocode:
int total = 0;
while ( !end_of_file )
{
char c = get character from user
if ( ! end_of_file )
{
int n = c - 30h;
total = total * 10 + n;
}
}
So, now, translating this to assembly is pretty
straightforward, except for a few minor points: