Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FLD instruction x64 bit

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.

like image 293
SMP3 Avatar asked Apr 03 '13 11:04

SMP3


People also ask

What does FLD instruction do?

The fld instruction sets the stack fault bit if stack overflow occurs. It sets the the denormalized exception bit if you load an 80 bit denormalized value. It sets the invalid operation bit if you attempt to load an empty floating point register onto the stop of stack (or perform some other invalid operation).

What is Fstp Assembly?

FSTP stores a floating point number from the top of the floating-point register stack ( ST0 ) to the designated memory region. Using the DWORD modifier means that a 32-bit float will be written. The P suffix indicates that the floating-point register stack will be popped after the operation.

What are FPU instructions?

The x87‭ ‬FPU instructions are executed by the so-called "math coprocessor"‬. ‭ ‬These instructions operate on floating-point,‭ integer,‭ ‬and binary-coded decimal (BCD) ‬operands. ‭ The main purpose of these instructions are to perform floating-point arithmetic.


1 Answers

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;
like image 138
GJ. Avatar answered Sep 19 '22 11:09

GJ.