News:

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

FMUL returning 0 - why?

Started by tomson123, February 02, 2012, 01:21:17 PM

Previous topic - Next topic

tomson123

I'm pretty new to asm... Basically, I just need to multiply two floating point numbers.
For some reason my fmul in my code is always returning zero... I can't seem to do it right and I'm trying my best for half a day now...
Fadd and Fsub are working all right, but when I change either of them to fmul, i get 0  :(
Here's some sample code to show what I mean:

.486
.model flat, stdcall
.data
number1   QWORD 21
number2   QWORD 2
result qword ?

.code

   finit

   fld number1
   fld   number2            
   fmul                           
   fst result   

end

I'm working on Windows 7, Intel's P7350 if that would be any help...
If you need any additional info, I will provide it.

Thank you in advance for your patience...

FORTRANS

Hi,

   How are you determining that the result is zero?  Could it just
be very small?  You have "QWORD 21" which will be interpreted
as an integer by the assembler,  not as a 21.0 float.  (Unless you
use FILD.)  That would be a very small real value when you use
FLD.

HTH,

Steve

jj2007

Steve is right. Use this:
   fild number1
   fild number2           
   fmulp                           
   fistp result   

tomson123

Thank you for you intrest :)
To be honest, i haven't really tried FILD... In every FPU tutorial, the syntax was FLD/FILD, without any explanation why, so i just thought of using the shorter version, for an obvious reason.
Unfortunately, this does not work either... I don't get 0 anymore, but almost the "exact" opposite now... It's some horrific >10digit number...
As to determining the value of "result", I'm using Visual Studio 2010 (asm is a part of a bigger, C++/winapi project)  and simply adding watch to the variables/registers i need.

If I have to, I could use some different variable types, but I need to return them as double/float later on, and I'm not sure if it would work...

jj2007

1. Select the Visual Studio folder
2. Press "delete" :lol

include \masm32\MasmBasic\MasmBasic.inc   ; download
.data
number1   QWORD 21
number2   QWORD 2
result   QWORD ?
resultR8   REAL8 ?
   Init

   fild number1
   fild number2
   fmulp
   fst resultR8
   fistp result
   Print Str$("The result as double is \t%f\n", resultR8)
   Inkey Str$("The result as integer is \t%i\n", result)

   Exit
end start

The result as double is         42.00000
The result as integer is        42

Seriously: It works. What is odd though is that the assembler does not throw at least a warning when you try to fld a qword ::)

P.S.: The lazy variant is Print Str$("The result as integer is \t%i\n", number1*number2)

tomson123

Quote from: jj2007 on February 02, 2012, 02:51:11 PM
1. Select the Visual Studio folder
2. Press "delete" :lol

True that :bg

Frankly, I really thought I would get away with it :) My project isn't really that hard, so i reckoned VS would be sufficient. I suppose i got what was coming to me :)
And no, it didn't throw any warnings  :eek
Thanks a lot, looks like I have to get a decent asm environment. Could you suggest somenting? Easy to handle is my priority :)

Again, thank you for all your help :)

jj2007

Quote from: tomson123 on February 02, 2012, 03:00:15 PM
Thanks a lot, looks like I have to get a decent asm environment. Could you suggest somenting? Easy to handle is my priority :)

Now that could open up a nice religious-ideological debate. Some use Notepad (seriously, and they are very good coders actually), the default editor here is \Masm32\qEditor.exe, I use RichMasm (part of MasmBasic), then there is RadAsm, GoAsm, VS, ... and many more. It depends strongly on personal experience and what you want to achieve. Professional programmers have different needs...

dedndave

RadAsm seems to be pretty nice, if you like integrated environments

tomson123

Thank you all :)
I am currently creating a project in RadAsm (since i have heard of it before, it was my pick). I hope it will make my life easier :)


dedndave

one nice thing about RadAsm - Ketil is continually improving it   :U

raymond

If you intend to continue using Fpu instructions, some of the very basic knowledge about the FPU would definitely "make your life a lot easier". How about reading at least the first two chapters of:

http://www.ray.masmcode.com/tutorial/index.html

If you think it may be of some use, the entire tutorial can be downloaded from the previous page so that you can have access to it offline.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com