News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Atoi

Started by HellOfMice, December 18, 2024, 08:00:56 PM

Previous topic - Next topic

HellOfMice

I kow him, he is is a nice italian programmer

Vortex

Hi Philippe,

Converting the atou_ex function from Masm64 to Poasm64 is very easy. The two versions are almost identical.

The method to convert a string to A number is handling correctly the Base-10 number system. To get the numerical value of a simple ASCII digit, one must extract 48 from this ASCII code. For example, the ASCII code of 5 is 53. 53-48=5
To shift each digit to the left, you multiply it by 10 :

    lea     r11, [r11+r11*4]       ;  r11=5*r11
    lea     r11, [rax+r11*2-48]  ;  r11=2*r11 + rax - 48


r11+r11*4 means multiplying r11 by 5. In the second line, after multiplying r11 by 2 , r11 becomes 10*r11 compared to the initial value of this register. The rest is easy, rax holds the ASCII digit and subtracting 48 from rax provides the numerical value.

The largest value of an unsigned 64-bit integer is 2^20 = 18446744073709551616. This means that a maxinum of 20 steps is necessary to convert correctly an ASCII string to integer.

Attached is a simple example, you can examine it with x64dbg to see how the algorithm works.
Code it... That's all...

HellOfMice

Hi Vortex

Thank you for your comments I learnt something:

Quotelea     r11, [rax+r11*2-48]  ;  r11=2*r11 + rax - 48
I did not know this was possible!


Thank you professor and Happy, merry christmas.


Philippe

HellOfMice

Surprising!


It is like this function only know to do one thing!


If you have others like this I take


Merci


Philippe

Vortex

Hi Philippe,

The Masm32 and Masm64 packages are providing a lot of useful funcrions. You can download the installers and study the help files shipped with them.
Code it... That's all...

HellOfMice

Yes that's right, I already downloaded it but the functions I looked at where not as much interesting than the atou_ex. I am looking at its code, not finished since you sent the post.
A gift for my 65 years birthday.


I wanted to answer to your MS-DOS header message, but you did not let me the time to do it. I answer into this one.
I think I saw interesting things into CCleaner header.


I will write a small program for using atou_ex and seeing how it works under the debugger.
Very good and thanks again Vortex


Philippe