Is it possible to define a floating point constant (`equ`) in NASM?

Viewed 128

In NASM, it's possible to define integer constants (equ), however, doing the same with floating point values causes an error:

section .data
    c1 equ 3       ; ok
    v2 dq  3.14    ; ok
    c2 equ 3.14    ; not ok: `my.asm:7: error: expression syntax error`

is it possible to define a floating point constant?

I've check the manual, but there's very little information.

1 Answers

No, equ doesn't work with non-integers. As fuz put it nicely:

The equ directive defines symbols. The value of a symbol is an address or an integer of the same size as an address.

Instead, you could use %define c2 3.14 to get text substitution of the macro at every point where you use it. (As opposed to equ which evaluates an expression once, at the location of the equ.)

That difference between equ and macros (including %define) matters for expressions like .len equ $ - v2 (because $ has a higher value later or in other sections), or involving something you change later with a %assign. But it doesn't matter for numeric literal constants; they always evaluate the same way everywhere.

Related