Does anyone have a good solution to this problem I have... Basically, as I've mentioned before I'm writing a code generator for a language and I'm trying to deal with floats. I've got all of the macros I need to actually work with the float once I get it into memory, however I'm having a problem getting it there! I know I can do this:

floatval dq 3.14159f

then I could use my macro on floatval... however I will have no way of knowing the value of the float I am storing since the ASM will be generated automatically... I thought I might be able to do something like this:

floatvaltmp dq ?

mov __floatvaltmp, 3.14159f

But FASM is unhappy with that. So the question is how would be the appropiate way to do this?

John
Posted on 2003-03-07 15:16:28 by coogle
Since you can only mov dwords, you can do mov dword ,3.14159f but I don't know if that would work right. You can also use FPU instructions, which is what I think is the only thing you can do. Like...

floatval dq 3.14159f
floatvaltemp dq ?

fld qword ;load it into st0
fstp qword ;mov floatvaltemp into st0, and pop the stack

But you can't do fld 3.1459f, it has to be a variable, dword or bigger.
Posted on 2003-03-07 16:08:41 by CyberGuy
So basically what I'm hearing is that I'm going to have the same problem with floats as I do with strings? i.e. I need to have a

tmpfloat1 dq 3.14159f
tmpfloat2..
tmpfloat3...

tmpstr1 db "Hello",0
tmpstr2 db "Goodbye",0

for every constant float/string that I have to process? That's frusterating, because it's just wasted memory since those constants will only be used once (when those values are stored into my memory manager)

John
Posted on 2003-03-07 16:12:33 by coogle
I think you can do something like this , unless its too big for a dword to handle

constant dd 3.14159f

fild dword ;load it into st0
fstp qword ;mov floatvaltemp into st0, and pop the stack
mov ,2.54
fild dword ;load it into st0
fstp qword ;mov floatvaltemp into st0, and pop the stack

and so on.
Posted on 2003-03-07 16:27:56 by CyberGuy
If you were a bit more specific about your meaning of "code generator" and what you are trying to achieve, it would certainly be easier to suggest something that could solve your "problem".

Raymond
Posted on 2003-03-07 20:15:21 by Raymond
This is incorrect, because there's no 64-bit move instruction avaiable:


floatvaltmp dq ?

mov [floatvaltmp], 3.14159f

But you can split it into two 32-bit instructions, altough to get the low and high dword of your value you need a small trick with virtual/load directives:


floatvaltmp dq ?

macro doubleconst name,value
{ name = value
virtual at 0
dq value
load name#.l dword from 0
load name#.h dword from 4
end virtual }

doubleconst pi,3.14159f

mov dword [floatvaltmp],pi.l
mov dword [floatvaltmp+4],pi.h
Posted on 2003-03-08 05:19:16 by Tomasz Grysztar
This is great Pivalov! Works like a charm. (although I'm not quite sure exactly how, maybe you can get a little explaination)? Can this technique be applied to string constants as well? It's a little more tricky I know since it's not as straightforward as lo/hi dwords... but if you had any tips :)

Regards!

John
Posted on 2003-03-08 09:02:55 by coogle