News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

how to write negative float value in MASM?

Started by supercoollee, May 07, 2010, 08:40:48 AM

Previous topic - Next topic

supercoollee

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.

dedndave

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

GregL

#2
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)


joemc

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 says you can and they are very reliable :)  why do you want to represent a negative number in hex?

GregL

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.


dedndave

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

supercoollee

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

Farabi

MASM Included a macro for FPU, CFLT and CDBL.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

supercoollee

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 .

MichaelW

Try:

function PROTO :REAL8,:REAL8,:REAL8

or

function PROTO :QWORD,:QWORD,:QWORD

eschew obfuscation

jj2007

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

supercoollee

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

supercoollee

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.

oex

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
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

oex

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
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv