defining a floating point value in data section from an equate

Started by Damos, July 19, 2009, 05:37:38 PM

Previous topic - Next topic

Damos

Can you help me please? i'm trying to do this:


ScreenResolutionX = 1024

.data
fScreenResolution      dd ScreenResolution.0


I need to generate a floating point value from a constant integer at assembly time.
Is this possible? A macro of some sort?
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction. - Albert Einstien

jj2007

No macro needed:

ScreenResolutionX = 1024
...
.data
fScreenResolution REAL4 @CatStr(%ScreenResolutionX, <.0>)

Damos

You're a star jj2007, thanks for the help. i'm working on a 2d tile game engine and i've just spent the last hour tring to do this, think I need to review some of my masm & macro knowledge. Thanks again.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction. - Albert Einstien

Neo

Does it not work with just:

ScreenResolutionX = 1024
...
.data
fScreenResolution REAL4 ScreenResolutionX


Or does that give some sort of unnecessary error?

jj2007

Quote from: Neo on July 20, 2009, 04:30:00 AM
Does it not work with just:

ScreenResolutionX = 1024
...
.data
fScreenResolution REAL4 ScreenResolutionX


Or does that give some sort of unnecessary error?

Try yourself:
include \masm32\include\masm32rt.inc

ScreenResolutionX = 1024

.code
fScreenResolution REAL4 ScreenResolutionX

start:
exit
end start


error A2187

Neo

Quote from: jj2007 on July 20, 2009, 07:57:18 AM
error A2187
Darn, that sucks.  :(

It won't give an error in Inventor IDE, but I can't recall if it encodes it as the integer 1024 or the floating point 1024 (I should fix it if it's not floating point).  It'll also let you do things like doing operations on a float in arbitrary constant expressions, like:
mov  eax,1.0/(1 shl 32) ;moves the floating point 1/(2^32) into eax

I think it'll use it as an integer on operations other than + - * / though, so like:
mov  eax,1.0 shr 23 ;moves the exponent of 1.0 into eax (7Fh)

Edit: It'll treat it as a double instead of a float in some cases, so 1.0 shr 23 may not be 7Fh; I should check back over that code, since it's been a while.  :wink

dedndave

it doesn't allow "ScreenResolution*1.0"
it would be nice if the assembler could just do math - lol


Neo

Quote from: dedndave on July 20, 2009, 09:00:47 AM
it doesn't allow "ScreenResolution*1.0"
it would be nice if the assembler could just do math - lol
That one's definitely supported in Inventor IDE.  In fact, you could define a constant ScreenResolutionFloat as "ScreenResolution*1.0", and when you hold Ctrl and run the mouse over the name, it'll show you "= 1024.0"  :8)

jj2007

Quote from: dedndave on July 20, 2009, 09:00:47 AM
it doesn't allow "ScreenResolution*1.0"
it would be nice if the assembler could just do math - lol
It does, it does...

MyCt = 5
MyDword dd MyCt*5
MyFloat REAL4 @CatStr(%MyCt*5, <.0>)

dedndave

yesssss - well i would hope it could multiply a real by an integer without catstr
could be useful for scaling
odd that i have never needed to do this
i guess it's because, once the assembler hiccuped on me, i would write code to do the conversion at runtime - lol