Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

moving ax into a variable

Status
Not open for further replies.

glogic

Programmer
Nov 8, 2001
15
0
0
IE
hi how u doing.. what i am trying to do is take in 2 digits and then place them in a variable.
i use mov ah,1 to take in the first didit which i then place in a db then i use another mov ah,1 to take in the second digit which places the character in al. i then place the stored db back into ah. i then want to place the whole double digit number into a variable dw so i use mov num,ax
what am i missing coz when i try running this it starts beeping like crazy or if u know of a better way of taking in a double digit decimal number will u please let me know.. thank u kindly in advance
 
"it starts beeping"

What is "it"?

Which assembler are you using? Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
sorry the machine was beeping that part wasnt imortant i just took it to mean that there was an error.. not sure what assembler can u give me examples and i will let u know which one sounds familiar.. sorry for not knowing something as simple as that but i am learning.. i swear!
 
What OS are you using? DOS? Windows?

Did you even return to your OS? "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
i am using dos and i am using tasm to compile the programs if that sheds any light on the subject
 
Did you even return to your OS?

How about posting a copy of your program? "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
ok here is what i have now. at the moment i have the decimal value i want in the variable but when i try and display it again it changes back to ascii..

mov ah,1
int 21h
sub ax,48
mov firstd,al

mov al,10
mul firstd
mov firstd,al

mov ah,1
int 21h
sub ax,48
add firstd,al
mov al,firstd
add al,48

mov ah,2
mov dl,al
int 21h
if the number i enter is 40 the value i get out is (.. any ideas
 
That's right

That's because DOS function 02h happens to expect an ascii value in dl.

Which basically means, you want to convert the numeric integer value in al into a string of ascii codes first... then output them using func 02h or 09h...
"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
i still aint getting it to work.. how do u convert to ascii codes.. and do i only need to do it before i output to the screen
 
Okay, let's put it this way. The values that mov ah,1; int 21h returns is acii. When you input the digits, what did you do to convert them to integers? So how do you put them back into ascii?

This is what you did:
mov ah,1
Int 21h
sub ax,48

So now what do you do?? "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
now i do what ever calculations i want with al and add 48 back to it to be displayed.

add al,48
mov ah,2
mov dl,al
int 21h

this should display the answer in decimal

 
Congratulations! You just did something very complex for assembly: print a number!

Now, wasn't that easy?

Your next mission, should you choose to accept it, is to print a number with more than one digit. Now, try making a program that can take a number between 0 to 65535 and print it on the screen.

And don't you DARE output something like:
00001
Cut out the zeroes!

Good luck! "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top