News:

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

FADD for calculations

Started by FlySky, July 04, 2007, 04:24:52 PM

Previous topic - Next topic

FlySky

Hey there guys,

I am just trying to do some calculations using the floating point stack. Here is my problem. I have a function pushing a certain amount on the stack. fld dword ptr [esi+0x490]. Than the FCHS function makes it minus to speak it the easy way. Than I have a FADD instruction doing the addition and pushing the result back on the stack. +- = - . How would I make that result always being 1. float. I have been thinking like this:

I push for example 20. float on the stack using the instruction FLD dword ptr [esi+0x490]. Than FCHS makes it -20 than the FADD is making it zero. So I was thinking before the FADD I add 1. float but how would I do that? Or can any tell me how I can calculate using FADD but making the result always end up with being 1. float.


u

if what you want to do is
result = var1+(-var1) + 1
then

fld1
fld var1
fld ST
fchs
; now ST(0) = -var1 ;  ST(1) = var1; ST(2) = 1
fadd
fadd
fstp result

Quite useless code
Please use a smaller graphic in your signature.

raymond

FlySky

You may want to have a look at the following tutorial if you intend to start using the FPU. It may save you a few headaches and accelerate your learning curve.

http://www.ray.masmcode.com/fpu.html

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

FlySky

Thanks for both replies guys,

I will start reading those FPU tutorials. I will keep you guys updated. It's the first time yeah that I am messing with the floating point stack this way.