I am taking input from the end user using the gets()
function and trying to convert that string to a number. From what I have found thus far, gets()
stores the address of the string captured in eax
but from there I am somewhat lost on how to convert it to a decimal. A few sources I have read have suggested to subtract 48 from the value stored, but that has not seemed to work for me. If this is how this is actually accomplished, I can follow this post up with a breakdown of my code.
Cheers!
Asked
Active
Viewed 59 times
0

Peter Cordes
- 328,167
- 45
- 605
- 847

Topher
- 1
-
Yes, for each digit you need to subtract 48 as that is the ascii code of 0. You will also need to scale by the appropriate power of 10. Note since you are using `gets` you seem to have the C library available so you may as well use its functions such as `sscanf` or `strtol`. – Jester Nov 10 '21 at 14:12
-
Or in fact use `scanf` in the first place so you don't need your own buffer to store a line of input. In [How to store user input from gets() in assembly?](https://stackoverflow.com/q/69911515) that wasn't being correctly, the code was passing a scanf format string to `gets`, instead of a pointer to a decent-sized buffer. – Peter Cordes Nov 10 '21 at 14:14