flat assembler
Message board for the users of flat assembler.

Index > Windows > [SOLVED] Impossible to initialize and use floating-point

Author
Thread Post new topic Reply to topic
xddj



Joined: 12 Apr 2019
Posts: 3
xddj 03 Jun 2025, 00:46
[PE64][Bug?] Impossible to initialize and use floating-point values in .data (always zero at runtime, Windows 11 + MSVCRT)

Hello everyone,

I’ve been struggling with what seems to be a long-standing bug or limitation in FASM PE64 under Windows (tested on Windows 11 and Vista x64, FASM 1.73.x and older versions):

**Whenever I declare a double-precision float (dq) in the .data section of a PE64 executable, its value is always 0.0 at runtime**—even though the memory is marked as readable/writeable and I follow all calling conventions for x64 (shadow space, stack alignment, etc.).

Here is a minimal code sample that *should* work according to the docs, but doesn’t:

Code:
format PE64 console
entry start

section '.data' data readable writeable
    val dq 42.78
    fmt db "DEBUG float = %.6f",10,0

section '.text' code readable executable
start:
    movsd xmm0, [val]
    mov rcx, fmt
    sub rsp, 32
    call [printf]
    add rsp, 32
    xor ecx, ecx
    call [exit]

section '.idata' import data readable writeable
    library msvcrt,'msvcrt.dll'
    import msvcrt, printf,'printf', exit,'exit'
    


No matter what I try (section alignment, putting value at start/end, using stack, shadow space, different printf, etc.),
the output is always 0.000000.
If I use int or strings in .data, they work fine; but floats and doubles are always zero.

What I’ve already tried:
Strict stack 16-byte alignment before call

Passing the value via stack, via register, via shadow space

Different FASM versions (old and new)

Allocating float on stack and passing its address

PE64 generated both with and without includes/macros

Running on Windows Vista, and Windows 11—all same result

On 32-bit PE, everything works perfectly (float/double is properly initialized and displayed).
Is this a known bug, or is there some undocumented trick to make floating-point data in .data work under PE64 with FASM?

Any advice, workaround or explanation would be much appreciated!

Thanks in advance,


Last edited by xddj on 03 Jun 2025, 01:19; edited 1 time in total
Post 03 Jun 2025, 00:46
View user's profile Send private message Reply with quote
Core i7



Joined: 14 Nov 2024
Posts: 111
Location: Socket on motherboard
Core i7 03 Jun 2025, 00:57
Code:
format  pe64 console
include  'win64ax.inc'
entry start

section '.data' data readable writeable
val   dq 42.78

section '.text' code readable executable
start:
      sub     rsp,8         ;<--------------
      movsd   xmm0, [val]
     cinvoke  printf,<' DEBUG float = %.6f',0>,[val]

     cinvoke  _getch
     cinvoke  exit,0

section '.idata' import data readable writeable
library  msvcrt,'msvcrt.dll'
import   msvcrt, printf,'printf', _getch,'_getch', exit,'exit'     
Post 03 Jun 2025, 00:57
View user's profile Send private message Reply with quote
xddj



Joined: 12 Apr 2019
Posts: 3
xddj 03 Jun 2025, 01:14
Thank you, it works perfectly! I had spent days trying to get this to work in pure FASM PE64 (manual stack alignment, direct calls to printf, etc.) and always got 0.0. I didn't realize that the advanced macros in `win64ax.inc` handle all the x64 calling convention/stack tricks behind the scenes.

Your example and explanation made it clear. This will definitely help anyone else facing the same issue!

Much appreciated!
Post 03 Jun 2025, 01:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 03 Jun 2025, 01:36
Better to use push rbp. No need for the longer, and less compatible, sub rsp,8.
Post 03 Jun 2025, 01:36
View user's profile Send private message Visit poster's website Reply with quote
xddj



Joined: 12 Apr 2019
Posts: 3
xddj 03 Jun 2025, 01:41
Thanks for the advice! I didn’t realize that `push rbp` was the preferred and more compatible way to align the stack. I’ll update my code accordingly. Much appreciated!
Post 03 Jun 2025, 01:41
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.