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.
Asked
Active
Viewed 976 times
0
-
1Use 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
-
1Thanks man! I wrote a simple atoi algorithm based on what you said, and it works nicely. – bjarke15 Mar 29 '18 at 10:20