×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

moving ax into a variable

moving ax into a variable

moving ax into a variable

(OP)
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

RE: moving ax into a variable

(OP)
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!

RE: moving ax into a variable

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."

RE: moving ax into a variable

(OP)
i am using dos and i am using tasm to compile the programs if that sheds any light on the subject

RE: moving ax into a variable

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."

RE: moving ax into a variable

(OP)
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

RE: moving ax into a variable

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."

RE: moving ax into a variable

(OP)
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

RE: moving ax into a variable

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."

RE: moving ax into a variable

(OP)
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

RE: moving ax into a variable

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."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close