how to divide two integers with floating point result

Started by rufus16, January 03, 2012, 10:45:11 PM

Previous topic - Next topic

rufus16

Hello.

Im quite new in this and i havent worked before with floating point operatoions before , therefore could someone show me snippet code

how do i divide two DWORD values from memory  with floating point result?

Thanks in advanced

qWord

.data
    i1 SDWORD 1234
    i2 SDWORD 10
    i3 QWORD 12345678912345
    f1 REAL4 ?
    d1 REAL8 ?
.code
    ; f1 = i1 / i2
    fild i1
    fidiv i2
    fstp f1
   
    ; d1 = i3 / i2
    fild i3
    fidiv i2
    fstp d1

The FPU doesn't support unsigned data types -> SWORD,SDWORD and SQWORD
FPU in a trice: SmplMath
It's that simple!

donkey

.DATA
Num1 DD 3
Num2 DD 12

.DATA?
Result REAL4 ?

.CODE
FILD Num1
FILD Num2
FDIV ST(1), ST(0) ;devide Num1 by Num2
FSTP Result ; store the result as a REAL4


Qword was quicker than I was, I was still trying to figure out MASM register names :)
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

raymond

If you are really interested in learning and doing it on your own, you can find a tutorial at:

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

Be sure to read the first two chapters. If you don't have such an interest, you could always use the FPU library available from the same link. It comes with an extensive help file and all the source code for each of the modules.

One of the functions in that library is for converting back from floats to ascii, which can be helpful until you decide to code your own. :dazzled:
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com