FLD instruction x64 bit

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

I have a little problem with FLD instruction in x64 bit ... want to load Double value to the stack pointer FPU in st0 register, but it seem to be impossible. In Delphi x32, I can use this code :

function DoSomething(X:Double):Double; asm    FLD    X    // Do Something ..   FST Result  end; 

Unfortunately, in x64, the same code does not work.

回答1:

In x64 mode floating point parameters are passed in xmm-registers. So when Delphi tries to compile FLD X, it becomes FLD xmm0 but there is no such instruction. You first need to move it to memory.

The same goes with the result, it should be passed back in xmm0.

Try this (not tested):

function DoSomething(X:Double):Double; var   Temp : double; asm   MOVQ qword ptr Temp,X   FLD Temp   //do something   FST Temp   MOVQ xmm0,qword ptr Temp end; 


回答2:

Delphi inherite Microsoft x64 Calling Convention. So if arguments of function/procedure are float/double, they are passed in XMM0L, XMM1L, XMM2L, and XMM3L registers.

But you can use var before parameter as workaround like:

function DoSomething(var X:Double):Double; asm   FLD  qword ptr [X]   // Do Something ..   FST Result end; 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!