Search code examples
assemblyx86nasmfpu

Can I get a int from my EAX/RAX to a register of the FPU like st0?


I am currently working on a small Assembler project in University. Now my question is, is it possible to get a skalar for a multiplication (int), which is given by the user, from my EAX/RAX Register to one of my FPU register like st0? I am using NASM Syntax.

Thank you


Solution

  • There is no way to directly transfer the content of an integer register to an x87 floating point register, you have to go through the memory. Typical code looks like this:

    PUSH RAX         ; push RAX on the stack
    FILD QWORD [RSP] ; load eight byte integer onto FP stack
    ADD RSP,8        ; release storage from stack
    

    You can usually avoid having to fiddle around with the stack pointer by allocating some storage for this sort of transfer in your stack frame at the beginning of your function.