2

I want to convert string representing floating point number to double (64bit ieee754) and store the result of conversion in the register RAX from assembly (using FASM). First of all I included library to my main.asm:

atof: jmp [imp_atof]
section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL',\
  user32,'USER32.DLL', \
  msvcrt, "MSVCRT.DLL"
include "macro\import64.inc"
   import msvcrt, \
   imp_atof, 'atof'

Next step is to call atof() in code:

push _buffer ;this is string buffer holding float number
call atof

After that something strange happening and I cannot understand what exactly. For example we need to convert -2309.12E-15. Result must be: BD844FAD0D676443. High result of the covert operation is right. It is stored in r8 register:

r8 = 00000000BD844FAD

But no one register store Low result. After debugging code calls I found that somewhere low result written to EAX register (000000000D676443) and then disappear. How can I resolve this problem?

Pavel Sapehin
  • 988
  • 12
  • 23
  • Parameters don't get passed on the stack in 64bit land, but in registers. Not sure what registers are used on Windows so consult Wikipedia for x86-64 calling conventions. – Gunner Dec 11 '14 at 21:39
  • Thanks, @cremno showed that it is stored in xmm0. But interesting that converted values appears at registers (eax, r8d) and also in YMM0I0 in one function call. I think there is must exist some performance issues. – Pavel Sapehin Dec 11 '14 at 22:19

1 Answers1

4

On Windows x64 the return value in this case is in XMM0. From the calling convention documentation on MSDN:

Non-scalar types including floats, doubles, and vector types such as __m128, __m128i, and __m128d are returned in XMM0.

cremno
  • 4,672
  • 1
  • 16
  • 27