moving data between general purpose and floating point registers


I am pretty new to assembly and I got the following problem. Frequently I have to calculate something in a general purpose register (say ECX), and then use the result in some floating-point calculations.

Let the example case be: having a number (dword, integer, signed) stored in ECX, divide pi by that number.

To do that I would do the following (in NASM syntax):

temp resq 1



fldpi ; store pi on the FPU stack
mov dword [temp], ecx
fild dword [temp] ; store temp on the FPU stack
fdivp st1, st0 ; divide ST1 by ST0 and pop the FPU stack

The problem is that to move data from one register on the CPU to another one we have to use external memory, which does not seem to be very efficient. I was trying to look for some magic opcode that would avoid the external memory part but without success.

Does anyone know whether some clever solution is possible, and if so, what it is?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!