NO

Author Topic: Atoi  (Read 1023 times)

Offline HellOfMice

  • Member
  • *
  • Posts: 232
  • Never be pleased, always improve
Re: Atoi
« Reply #15 on: December 20, 2024, 09:10:10 PM »
I kow him, he is is a nice italian programmer
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 909
    • http://www.vortex.masmcode.com
Re: Atoi
« Reply #16 on: December 24, 2024, 05:25:15 PM »
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 :

Code: [Select]
    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...

Offline HellOfMice

  • Member
  • *
  • Posts: 232
  • Never be pleased, always improve
Re: Atoi
« Reply #17 on: December 24, 2024, 05:55:52 PM »
Hi Vortex

Thank you for your comments I learnt something:

Quote
lea     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
--------------------------------
Kenavo

Offline HellOfMice

  • Member
  • *
  • Posts: 232
  • Never be pleased, always improve
Re: Atoi
« Reply #18 on: December 24, 2024, 06:00:24 PM »
Surprising!


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


If you have others like this I take


Merci


Philippe
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 909
    • http://www.vortex.masmcode.com
Re: Atoi
« Reply #19 on: December 24, 2024, 06:09:53 PM »
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...

Offline HellOfMice

  • Member
  • *
  • Posts: 232
  • Never be pleased, always improve
Re: Atoi
« Reply #20 on: December 24, 2024, 06:16:32 PM »
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
--------------------------------
Kenavo