Hi, I solved the problem by using:

***
;DIVML divides Sour with Dest and saves the results in Dest

DIVML MACRO Dest, Sour
MOV EAX, Dest
CDQ
MOV ECX, Sour
IDIV ECX
CWDE
MOV Dest ,EAX
ENDM

***

devilsclaw - The version I have returns 0 errors when used, your does not do that. Your macro actually has some mistakes.

Though there is one problem when I make it divide 7 by 2 it does not return 3.5 but 3. that's actually not precise. But when I use 12.534 it should return 6.267 but it only returns 6. Now that is not good at all. Specially for what numbers my macro is gonna use.
So what shall I do to support atleast 2 decimals after the "."?
Shall I make it work for QWORD? OR maybe even higher?
Please give me the hole macro. Thanks.
Posted on 2003-09-23 13:00:43 by JulianS
yeah i said you might of needed to flip the Dest and Sour ... yours flips them around other then mine..
Posted on 2003-09-23 13:04:11 by devilsclaw
devilsclaw how can I make it use more decimals?
Posted on 2003-09-23 13:40:06 by JulianS
JulianS

As a "general rule", you cannot get fractional results with integer maths. Either you use the FPU to do floating point maths or you design a fixed point math library with some limitations. You can find an example of such a library (Mix.lib) as the last item at the following site (the source code is included in the .zip file):

http://www.movsd.com/source.htm

Raymond
Posted on 2003-09-23 20:16:22 by Raymond
Raymond - Hi I have simplified all the macros except DIVML, by using FPOpcodes, is that good? I mean they do float point math right?

Here my current DIVML:

***

;DIVML divides Sour with Dest and saves the results in Dest
DIVML MACRO Dest, Sour
MOV Dest, EAX
MOV EAX, Dest
CDQ
MOV ECX, Sour
IDIV ECX
CWDE
MOV Dest ,EAX
ENDM

***

I need it to use more decimals. Maybe by using a FPOpcode(FDIV/FIDIV)? I tried with FDIV and FIDIV and none of them worked. There always seemed to be more errors. Can anybody telll me how to use them?
Posted on 2003-09-24 10:04:46 by JulianS
There are 2 different approaches to using the FPU for math operations:

1) Program the FPU yourself but learn beforehand how to use it. You may want to start with the following tutorial:
http://www.masmforum.com/website/tutorials/fptute/index.html

2) Use a library of math functions such as the FPULIB supplied with the latest MASM32 package. It has an extensive Help file describing how to use each of the functions in a style similar to the WinAPI Help files. That FPULIB package is also available from this forum, the latest version 1.2 being near or at the end of the following thread:
http://www.asmcommunity.net/board/index.php?topic=9717&highlight=fpulib

Raymond
Posted on 2003-09-24 12:15:09 by Raymond
Raymond, I don't really understand how FP Opcodes works, even after reading the web you provided me with:(. Now that I try to test the code none of my macros works. Damm. Could you or somebody else make these macros or at least give me a url/http address that can make the macros using FP help me?

Posted on 2003-09-24 15:26:15 by JulianS
JulianS

As a starter, why must you absolutely insist on using macros for those operations?:confused:

If you use the suggested Fpulib (and have your system properly set up such as with MASM32), and you want your answers with 2 decimal places, the following example code would divide the content of the EAX register by the content of the EDX register and put the answer as a null-terminated string in the buffer of your choice:
invoke FpuDiv,eax,edx,0,SRC1_DIMM or SRC2_DIMM or DEST_FPU

The above is just one example of usage (you do not need to use the EAX and EDX registers). The functions are quite flexible but you have to understand the requirements for the parameters and supply the required information.

Raymond
Posted on 2003-09-24 19:05:42 by Raymond
Indeed, making macros would be somewhat complicated and restrictive since the FP instructions use either the FPU stack or a memory variable, but not the registers. I guess you could do something like this, but I do not see much gain in it...
FPMUL macro result,factor1,factor2

; Multiplies two integers, returns real.
; USE VARIABLES, NOT REGISTERS.
fild factor1
fimul factor2
fstp result
fwait
endm

I'll leave you the division macro as homework... ;)
Posted on 2003-09-24 21:30:22 by QvasiModo
fstp result
This instruction would store the result as either a REAL4, a REAL8 or a REAL10 (in floating point format) depending on the declared size of the memory variable result. Somehow, I don't think that would be of much help to JulianS at this stage.

Raymond
Posted on 2003-09-24 22:44:58 by Raymond
Raymond - I insist on using macros cause I am gonna put these macros in my ML(Math Language) Program.
If I use a libary I would make my program dependent. I want it to be independent so I won't use "FPU Functions" but "FP Opcodes".

QvasiModo -
So DIVML: would be:

***

DIVML macro Dest, Sour

FILD Dest
FIMUL Sour
FSTP Dest
FWAIT

ENDM

***

and a MULML with less operands would be:

***

MULML macro Dest, Sour

FILD Dest
FIMUL Sour
FSTP Dest
FWAIT

ENDM

***

I guess they are wrong cause when they're compiled they don't work(Atleast the DIVML don't).
Please tell me what's wrong. Note that it reports something like: "Error A2001: Emmediate operand not allowed"

Quick results or Posted on 2003-09-25 09:49:33 by JulianS
operand is a value that you tell the opcode to use i see there all dword memory placements it has to read from...
try moving them to a register and then point the opcode to that register..
Posted on 2003-09-25 13:21:24 by devilsclaw
If I use a libary I would make my program dependent.

When you assemble and link a program using library functions, the code of these functions gets inserted in your program in the same manner as whatever other code you wrote yourself. Your final program is NOT dependant on the library.

Relying on a DLL would be totally different. Those functions are not inserted in your program which would then be dependant on that DLL being available on your system.

Raymond
Posted on 2003-09-25 15:59:49 by Raymond
Originally posted by Raymond:
This instruction would store the result as either a REAL4, a REAL8 or a REAL10 (in floating point format) depending on the declared size of the memory variable result. Somehow, I don't think that would be of much help to JulianS at this stage.

Replace with this, then:
fistp result

However, there's not much difference with the previous version... I was just giving him a little "push" towards FP instructions, by showing him an example. :)
Posted on 2003-09-25 17:47:50 by QvasiModo
In a nutshell, then :) :

FISUB: Substract integer to previously loaded number.
FSUB: Substract FP to previously loaded number.

FIMUL: Multiply integer with previously loaded number.
FMUL: Multiply FP with previously loaded number.

FIDIV: Divide integer by previously loaded number.
FDIV: Divide FP by previously loaded number.

FISTP: Store integer.
FSTP: Store floating point number.

You should:
2) Operate with the second parameter.
3) Store the result.

Always use memory operands (NOT registers). It would also be good to put FINIT at the beginning of the code generated by your program, to reinitialize the floating point unit (that is, clean up anything that might have been on it). You only need to do that once.

Note that we're loading only one number at a time here. For more complicated stuff (loading several numbers, changing the rounding mode, etc.) you will need to take a look at Raymond's excellent FPU tutorial.
Posted on 2003-09-25 17:55:01 by QvasiModo
Is this right?

***

DIVML macro Dest, Sour

FILD Dest
FIMUL Sour
FISTP Dest
FWAIT

ENDM

***

I haven't tested it. Do I need to use registers?
:confused:

Posted on 2003-09-26 14:52:04 by JulianS
Patience! :grin:
Take a closer look at my previous post... see what it says about FMUL? It is to MULTIPLY. So why are you using it in your DIVISION macro?
Try to calm down a bit... what is the rush anyway? If you simply copy & paste the code we give you without understanding it, what good is it for you? If you need to change for whatever reason, you can't. You need to know what you're doing in your own program :)
Posted on 2003-09-26 17:27:55 by QvasiModo
Is this right then?

***

DIVML macro Dest, Sour

FILD Dest
FIDIV Sour
FSTP Dest
FWAIT

ENDM

***
Posted on 2003-09-27 02:51:34 by JulianS
That's right, this is the equivalent of (pseudo-HLL):

Dest := Dest / Source
Posted on 2003-09-27 16:56:21 by QvasiModo
I tried using the function with a number and a DWORD from the start of a proc(Proc MyDWORDToUse:DWORD)
It coulden't compile, cause it returned some errors. You could try it yourself to get a better understanding of what the errors are about.

Julian.
Posted on 2003-09-29 08:50:22 by JulianS