The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: supercoollee on May 07, 2010, 08:40:48 AM

Title: how to write negative float value in MASM?
Post by: supercoollee on May 07, 2010, 08:40:48 AM
i know i can predefine some float values in .data
but if i want to input instant value, how should i write it?

i tried this:  invoke functionname,3f800000h,0,bf800000h

here 3f800000h is interpreted into hex 3f800000, but bf800000h can't be assembled.

i also tried -3f800000h, a wrong value was produced. how should i write the right value?

i also tried invoke functionname,1.0,0,-1.0   . this can't be assembled either.
Title: Re: how to write negative float value in MASM?
Post by: dedndave on May 07, 2010, 09:10:37 AM
when hexidecimal values begin with a non-numeric character, they must be preceeded with a 0: 0bf800000h
otherwise, the assembler thinks it is  a label of some sort
labels, on the other hand, may not begin with a numeric digit
Title: Re: how to write negative float value in MASM?
Post by: GregL on May 07, 2010, 05:02:11 PM
INVOKE can't accept floats directly like that. MASM32 includes some macros for doing what you want called FP4, FP8 and FP10. You use them like this: 

  INVOKE functionname, FP8(1.0), FP8(0.0), FP8(-1.0)

Title: Re: how to write negative float value in MASM?
Post by: joemc on May 08, 2010, 02:44:39 AM
i didn't know you could write negative numbers in hex using the minus sign :) i thought you just had to make sure the negative bit was set. ... but wikipedia (http://en.wikipedia.org/wiki/Hexadecimal) says you can and they are very reliable :)  why do you want to represent a negative number in hex?
Title: Re: how to write negative float value in MASM?
Post by: GregL on May 08, 2010, 03:56:01 AM
From the MASM Programmer's Guide:

; Encoded as hexadecimals
ieeeshort       REAL4    3F800000r             ; 1.0 as IEEE short
ieeedouble      REAL8    3FF0000000000000r     ; 1.0 as IEEE long
temporary       REAL10   3FFF8000000000000000r ; 1.0 as 10-byte real

I've never done it that way, but I guess it's possible.  It doesn't show an example of negatives.

Title: Re: how to write negative float value in MASM?
Post by: dedndave on May 08, 2010, 04:12:00 AM
it is very time-consuming to do it that way, but it can be done
for floats, there is no 2's compliment - just take the same positive value and set the sign bit
why do that way when the macros are there for ya - lol
if you do it by hand, you are more likely to make a mistake
Title: Re: how to write negative float value in MASM?
Post by: supercoollee on May 08, 2010, 05:16:56 AM
i didn't know i could write:
INVOKE functionname, FP8(1.0), FP8(0.0), FP8(-1.0) . now this is great!

i wrote hex only because invoke functionname,1.0,2.0,3.0  can't be assembled.
and some float values are very easy to remember , such as 0, 0.5, 1 and -0.5, -1
Title: Re: how to write negative float value in MASM?
Post by: Farabi on May 08, 2010, 05:53:44 AM
MASM Included a macro for FPU, CFLT and CDBL.
Title: Re: how to write negative float value in MASM?
Post by: supercoollee on May 08, 2010, 07:01:50 AM
i find INVOKE functionname, FP8(1.0), FP8(0.0), FP8(-1.0)  can't help the situation when a function PROTO is like this:
function PROTO :dword,:dword,:dword,:dword,:dword,:dword

i still have to predefine 3 double values in .DATA , then
invoke function dword ptr predefined1,dword ptr predefined1+4,dword ptr predefined2,dword ptr predefined2+4,dword ptr predefined3,dword ptr predefined3+4

and FP4(1.0) is actually assembled the same way as if a float value was predefined in .DATA .
Title: Re: how to write negative float value in MASM?
Post by: MichaelW on May 08, 2010, 07:26:46 AM
Try:

function PROTO :REAL8,:REAL8,:REAL8

or

function PROTO :QWORD,:QWORD,:QWORD

Title: Re: how to write negative float value in MASM?
Post by: jj2007 on May 08, 2010, 07:35:39 AM
Quote from: supercoollee on May 08, 2010, 07:01:50 AM

and FP4(1.0) is actually assembled the same way as if a float value was predefined in .DATA .


Not by accident:
      FP4 MACRO value
        LOCAL vname
        .data
        align 4
          vname REAL4 value
        .code
        EXITM <vname>
      ENDM


\masm32\macros\macros.asm is a fascinating lecture :wink
Title: Re: how to write negative float value in MASM?
Post by: supercoollee on May 08, 2010, 07:44:43 AM
Quote from: MichaelW on May 08, 2010, 07:26:46 AM
Try:
function PROTO :REAL8,:REAL8,:REAL8
or
function PROTO :QWORD,:QWORD,:QWORD

i didn't mean the protos which can be defined by me, i meant the predefined protos such as

gluPerspective proto :dword,:dword,:dword,:dword,:dword,:dword

this function requires 3 real8 value, but in opengl32.inc , it requires 6 dwords  :tdown
Title: Re: how to write negative float value in MASM?
Post by: supercoollee on May 08, 2010, 08:08:46 AM
Quote from: jj2007 on May 08, 2010, 07:35:39 AM
Quote from: supercoollee on May 08, 2010, 07:01:50 AM

and FP4(1.0) is actually assembled the same way as if a float value was predefined in .DATA .


Not by accident:
      FP4 MACRO value
        LOCAL vname
        .data
        align 4
          vname REAL4 value
        .code
        EXITM <vname>
      ENDM


\masm32\macros\macros.asm is a fascinating lecture :wink

now that i find out this fact, i will stick to my way - writing immediate HEX value in the code, that's faster than FP4(1.0) in runtime, although the difference is small.
Title: Re: how to write negative float value in MASM?
Post by: oex on May 08, 2010, 08:23:51 AM
It will likely be easier for you to use FP4/8/10/etc(x.x)

Reason being that once you start entering 'normal' numbers you dont have to convert.... ie point:

What is 608.735629 in HEX in the time it takes you to type FP4(608.735629)?

Further when you read that number in hex how long does it take you to know what the value is
Title: Re: how to write negative float value in MASM?
Post by: oex on May 08, 2010, 08:26:43 AM
Quote from: supercoollee on May 08, 2010, 07:44:43 AM
i didn't mean the protos which can be defined by me, i meant the predefined protos such as

gluPerspective proto :dword,:dword,:dword,:dword,:dword,:dword

this function requires 3 real8 value, but in opengl32.inc , it requires 6 dwords  :tdown

You'll have to ask Farabi on this.... I think he uses glu.inc instead.... I wrote navigation some more complex way without which I still dont completely get :lol
Title: Re: how to write negative float value in MASM?
Post by: dedndave on May 08, 2010, 01:38:29 PM
Quotei find INVOKE functionname, FP8(1.0), FP8(0.0), FP8(-1.0)  can't help the situation when a function PROTO is like this:
function PROTO :dword,:dword,:dword,:dword,:dword,:dword

that's because you are using 4-byte floats   :bg
try this, instead...

INVOKE functionname, FP4(1.0), FP4(0.0), FP4(-1.0)
Title: Re: how to write negative float value in MASM?
Post by: Farabi on May 08, 2010, 02:07:33 PM
Put this above all of your include file.


literal_double macro lit_double:vararg
local local_double

.data
local_double real8 lit_double

.code
exitm <local_double>
endm

literal_float MACRO lit_float:VARARG
LOCAL local_float
.data
local_float real4 lit_float
.code
EXITM <local_float>
ENDM

CFLT MACRO lit_float:VARARG
EXITM <literal_float(lit_float)>
ENDM


CDBL macro lit_double:vararg
exitm <literal_double(lit_double)>
endm


This is how do you use it

invoke glVertex3f,CFLT(1.0),0,0
Title: Re: how to write negative float value in MASM?
Post by: GregL on May 08, 2010, 07:31:56 PM
.
Title: Re: how to write negative float value in MASM?
Post by: joemc on May 08, 2010, 07:42:30 PM
just use directx.  I have switched myself. mostly because AutoCAD did. Whats good enough for them is good enough for me.
Title: Re: how to write negative float value in MASM?
Post by: supercoollee on May 09, 2010, 03:10:24 AM
is there some extra requirements for using directx instead of opengl?
currently i only have MASM32 package downloaded from Hutch's site. this IDE is simple and lightweight and doesn't mess with my system. i like this kind of environment.  :thumbu
in fact, what i need is just an IDE which helps me create a standalone software, i don't need much fancy stuff, i don't like softwares which are 1GB in size.  :snooty:
Title: Re: how to write negative float value in MASM?
Post by: Farabi on May 09, 2010, 03:23:42 AM
Quote from: supercoollee on May 09, 2010, 03:10:24 AM
is there some extra requirements for using directx instead of opengl?
currently i only have MASM32 package downloaded from Hutch's site. this IDE is simple and lightweight and doesn't mess with my system. i like this kind of environment.  :thumbu
in fact, what i need is just an IDE which helps me create a standalone software, i don't need much fancy stuff, i don't like softwares which are 1GB in size.  :snooty:


Try using RadAsm.