0

You can convert single digits from ASCII to number by simply subtracting '0'. To convert a multiple digit number, I guess you could count the number of digits and and multiply each digit by a power of ten corresponding to its position and sum all these to get the final number. But I'm wondering if there is any compact way to do this in x86-16 assembly.

2
  • 2
    Use a loop to implement tmp = 0; for() { tmp = tmp*10 + (*digits++)-'0'; } in asm however you like, with appropriate loop boundaries. i.e. the usual atoi algorithm. If you can use 32-bit addressing modes, you can multiply by 10 + add in 2 LEA instructions. Commented Mar 29, 2018 at 2:20
  • 1
    Thanks man! I wrote a simple atoi algorithm based on what you said, and it works nicely. Commented Mar 29, 2018 at 10:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.