Home > Back-end >  Is there a way to assign a floating point immediate to a register
Is there a way to assign a floating point immediate to a register

Time:11-08

As far as I know, it is not possible to move a floating point number directly in a register using a single instruction, like so:

fld 0.5

or

movsd xmm0 , 0.4 

I'd like to make a macro storing a floating point value to memory and then to the register, like this:

%macro fld_macro 1  

section .data 

_%1 : dq %1

section .text 

fld qword [_%1]

%endmacro 

My issue is that I want to first check if the value already exists before I execute the macro. Something along the lines of:

%macro fld_macro 1  

(if _%1 doesnt exist   , then )

section .data 

_%1 : dq %1

section .text 

fld qword [_%1]

(else )

%endmacro 

Is that possible? i am using nasm (-fwin64 ) and gcc

CodePudding user response:

As far as i know , it is not possible to move a floating point number directly in a register using a single instruction , like so

For most values, it's not possible.

The 80x86 FPU does have support for loading some common constants ( 0.0, 1.0, PI, ...) in a single instruction (without any immediate). You can see the full list and their details in the manual (or here: https://www.felixcloutier.com/x86/fld1:fldl2t:fldl2e:fldpi:fldlg2:fldln2:fldz ).

id like to make a makro storing a floating point value to memory and then to the register , like this :

my issue is that i want to first check if the value already exists before i execute the macro . something like bellow

I don't think you can; at least not in a robust manner. The problem is that the preprocessor works on strings, and (e.g.) the string "1.0" is different to the string "1.00" so (assuming you can use string concatenation in a

  • Related