Author Topic: Store float into memory  (Read 16094 times)

nobody

  • Guest
Store float into memory
« on: April 15, 2008, 12:51:35 AM »
Hello,
it may be a really stupid question, but I don't know how to store float type variable into memory:(
The code is really simple:

first I'm loading a variable from an array of floats (yes, the C float variable, usually 4 bytes long)

fld     dword [eax]
    fld     dword [eax+4]

next, some operations are performed, such as:

fmul    st1

now, I have to store the result in the same array. But it's not that simple:

fstp    qword [eax]

would store the whole qword (8 bytes) in the memory, but I need a variable of 4 bytes size! The result is not located in any of the halves of ST0.

What should I do????

nobody

  • Guest
Re: Store float into memory
« Reply #1 on: April 15, 2008, 01:16:23 AM »
fstp dword [eax]?

Internally, the FPU is 80-bits ("extended precision" - one C doesn't know). But you can fld and fst(p) into 4, 8, or 10 bytes. If you've got a single precision float, and you want to print it with printf... printf always wants double precision! So...

fld dword [my_single_precision] ; if not there
sub esp, 8
fstp qword [esp]
push format_string
call printf
...

and that "converts" your single to double...

Best,
Frank

nobody

  • Guest
Re: Store float into memory
« Reply #2 on: April 15, 2008, 07:04:36 AM »
`printf always wants double precision!' - and that's what doomed me... I thought that if the number doesn't display correctly, then something has got to be wrong.

Thank You very much:)