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.

bjarke15
  • 85
  • 5
  • 1
    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. – Peter Cordes Mar 29 '18 at 02:20
  • 1
    Thanks man! I wrote a simple atoi algorithm based on what you said, and it works nicely. – bjarke15 Mar 29 '18 at 10:20

0 Answers0