1

I want to simply get the user to input a number. I can get input (I think), but this is a string, and I need to convert it to a number (DWORD). I couldn't find anything that worked in MASM. I tried the C functions strtol and atoi, but it couldn't find them. Is there some function that works in MASM? Or do I have to write my own conversion?

I tried several include files, but I couldn't get the C functions:
windows.inc
kernel32.inc
user32.inc
msvcrt.inc

2 Answers 2

1

Its over 20 years since I used MASM so I'm a bit rusty. The algorithm is pretty straightforward though.

  • Assuming your string is in ASCII
  • Start at the end of the string
  • You will need to split each character off the string and subtract 30H from it to give the digit
  • store that digit in a register
  • calculate your next power of ten
  • Each time you move one character left and get that digit multiply by the next power of ten
  • add to accumulator

E.g for an integer

31H 32H 33H

31h-30H = 1H 32H-30H = 2H * 10 33H-30H = 3H * 10 * 10

Bingo!

If the number represents a double you will need to cope with in a similar manner.

Sign up to request clarification or add additional context in comments.

4 Comments

sooo... there's no function to do it for me?
If you want to call atoi you would need to include the C runtime libraries rather than the Windows libraries
Would that be msvcrt.lib? I tried both the .lib and the .inc, but it said undefined symbol. Maybe it is in the .lib but not the .inc, and I need to proto define it.
Ok, I went atoi PROTO C strptr:DWORD and includelib'ed msvcrt.lib and it worked!
0

I did atoi PROTO C strptr:DWORD and then I was able to call atoi.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.