elflyao
elflyao

Reputation: 387

How to emit floating point immediate operand using decimal representation in gnu assembler

For example, 0.5f is 0x3F000000 in the target platform. I want to use something like movl $0.5,%eax instead of movl $0x3F000000,%eax

The assembler is from TDM-GCC.

Upvotes: 2

Views: 451

Answers (1)

phuclv
phuclv

Reputation: 41805

You need to declare a separate constant with either .float, .single or .double directives

For example

.data
        half: .float 0.50
.text
.globl _start
        _start:
        movl half, %eax

https://en.wikibooks.org/wiki/X86_Assembly/AVX,_AVX2,_FMA3,_FMA4

You can also use E/F/G/H constraints in inline assembly

static const float half = 0.5f;
__asm__ __volatile__ ("\n\
   movl %1, %eax        %1"
   : "g" (half)
   ) ;

Upvotes: 2

Related Questions