News:

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

Convert SDWORD to real8 in asm file

Started by Gaurav, March 04, 2010, 04:52:27 PM

Previous topic - Next topic

Gaurav

Thanks it works now.. but result is weird


Enter number: 5
Enter exponent: 5
...
The value of power is: -1.#IND00


Is the result translated to hex values?
The result should be 3125...

MichaelW

The IND in the result means indefinite. I have a listing somewhere of these error results and what they mean, but I can't seem to find it.

Your code is mixing incompatible data types. StrToFloat returns a REAL8, and FpuXexpY cannot directly handle a REAL8. Since your code is displaying the value of n2 with str$, I assumed that n2 is supposed to be a 4-byte integer. So to input it I used:

invoke atodw, input("Enter exponent: ")
mov n2, eax


And to load it from memory and store it back:

fild n2
...
fistp n2


And since the destination for FpuXexpY apparently defaults to DEST_MEM, I removed the:

fstp power

And with those changes the code appears to work correctly.
eschew obfuscation

Gaurav

Ok, I changed the code to floating-point and it's good! Here's the bit of coding:


.386                            ; create 32 bit code
.model flat, stdcall            ; 32 bit memory model
option casemap :none            ; case sensitive

include \masm32\include\masm32rt.inc
include \masm32\fpulib\Fpu.inc
includelib \masm32\fpulib\Fpu.lib

.data
n1 REAL10 ?                     ; the first value
n2 REAL8 ?                      ; the second value
power REAL10 ?                  ; the result of n1^n2

.code
start:

    finit                       ; initialize fpu

    invoke FpuAtoFL, input("Enter Float Value: "), ADDR n1, DEST_MEM
    invoke StrToFloat, input("Enter Exponent: "), OFFSET n2
   
    fld n1                      ; pushes n1 to stack
    fabs                        ; make it positive if needed
    fstp n1                     ; store it back and pop
    fld n2                      ; pushes n2 to stack
    fabs                        ; change to positive if needed
   
    invoke FpuXexpY, ADDR n1, 0, ADDR power, SRC1_REAL or SRC2_FPU
   
    print chr$(10, "The result is: ")
    print real10$(power)
    print chr$(10)

inkey
exit
end start


Thank you all for helping!
Now if only I can find the same XexpY for integers.. that would be awesome!

raymond

Michael,
Quoteand FpuXexpY cannot directly handle a REAL8

The latest version of the Fpulib has been expanded to accept REAL4 and REAL8 as input and output. It is not restricted anymore to using REAL10 throughout.

The latest version is always available from:
http://www.ray.masmcode.com/fpu.html#fpulib

Note that the Fpulib made available on other sites (or with the MASM32 package) is never guaranteed to be the latest version.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com