Hey guys! I am just getting started in assembly language and my head hurts from staring at this problem. I'll paste in the program requirements, then my program and show where I am stuck...any help would be appreciated..I have a test in 7 hrs!!
Problem:
Number Conversion
In this lab, you will be converting a sequence of characters read from the console into a simple unsigned integer number.
You will need four sections in your program:
Part 1 - Sign on
Print out a simple program message with the name of your program and a prompt for the user to enter an integer number. We will ask the user to type in at most four digits only. You may assume (never a good idea in real life) that the user is smart, and only enters what you ask: four or less digits followed by the Enter key. (No error checking is needed beyond this).
Part 2 - Getting user data
Read the user input using the get_kb routine defined in the C library (include the asm_io line for this to work). This routine returns a single character in the EAX register - only the low 8 bits (AL) are of interest. This routine does not echo the character the user typed on the screen - if you want that to happen, you will need to use the print_char routine to make that happen.
Part 3 - Converting the characters to numbers
The character you get from the user ends up in the AL register as a binary number that is the ASCII code for the key pressed. You will need to convert this code into the right numerical value (look at the ASCII code table and you will see that the digits are in order starting at a code of 30h. So to convert the code for the digit 3, we could subtract 30h from that code and we would get a binary value of 3. Sound right?
Think about how you would do the rest of the conversion. You will see the user’s digits left to right. How can you form the answer?
You will probably need to look up the instruction to multiply an integer by another integer to figure this out (Try this: oldnum = oldnum * 10 + new num. That should get you started)
Part 4 - Print out the answer
Once you have the number converted, use the print_int routine from your library to display the result. You should see the number the user typed in.
------------------------------------
My code so far:
_asm_main:
enter 0,0
mov eax, message
call print_string ; display startup message
call print_nl
call print_nl
mov eax, prompt ; prompt user for number
call print_string
call print_nl
number_entry:
call get_kb ; read keyboard input
call print_char ; displays first digit
cmp al, 0dh ; end of user input?
jne number_entry ; if not, loop again
sub al, 30h ; subtracts hex 0 from hex input
mov bl, al ; copies what user input to memory
call print_nl
mov eax, message2
call print_string
convert_number:
-------------------------------------
so I can input, and echo user input. What's not making sense is how I deal with what is put into the AL register and how I manipulate it bit by bit. Also I vaguely recall reading that an ASCII character is a byte long so when the character that is input by the user is saved to AL is it a byte long? SO CONFUSED!!! please help