Click to See Complete Forum and Search --> : Multiply number with decimal point
zifeer
May 6th, 2006, 05:04 AM
Hi,
How can I use a number containing a decimal point using MUL (or IMUL). I want to multiply 3.14 to calculate the area of a circle but I can't figure out how.
Thank you.
nolxev
May 6th, 2006, 05:24 AM
MUL and IMUL are ALU (arithmetic logic unit) instructions, you can't use 3.14159, you have to lean FPU (floating point unit) instructions to do that.
zifeer
May 6th, 2006, 05:59 AM
I didn't understand what you meant by "lean FPU" could you please elaborate more?
PS: I use MASM615 for assembling.
zifeer
May 6th, 2006, 06:27 AM
Never mind, I got it. I should use FMUL instead of MUL or IMUL.
Thank you :)
zifeer
May 7th, 2006, 08:48 AM
Can you please give me an example on using fmul. I've read about it but I still don't understand how to use it.
nolxev
May 7th, 2006, 03:01 PM
I have not a FMUL example here but trust me, try to not study FPU programming by examples, start with learn how FPU works and its instructions.
zifeer
May 8th, 2006, 08:07 PM
I think I understand how it works, but my problem is printing the result on screen. In Irvine32.inc there're procs like WriteInt and WriteDec but these do not show the correct result. How can I make my program print the correct float number?
nolxev
May 9th, 2006, 04:44 PM
Display float number is no so easy in ASM, the interrupt can only display characters not floating numbers, you can always mix your ASM code with C one and write in C language that function.
zifeer
May 11th, 2006, 08:26 PM
So it's not possible using only asm?
If not, how can I embed C (or C++) into asm?
nolxev
May 12th, 2006, 09:32 AM
It's possible using only ASM, but it's too hard. To mix with C/C++ code you should read your compiler documentation, it depends on what compiler you're using, VC++, gcc and so forth uses different methods.
yeohhs
May 13th, 2006, 04:09 AM
Hi,
I'm using RosAsm, the FPU asm code is quite easy. :)
This simple Win32 example program multiplies val1 with val2, displays the result and then multiplies the result with val3 and displays it. It shows how to use fmul and fimul.
; Data:
[formatf: B$ "%f",0]
[buffer: B$ ? #128]
[val1: R$ 3.141593]
[val2: R$ 1.32]
[val3: D$ 10]
Main:
finit
fld R$val1
fmul R$val2
fstp R$val1
mov eax, val1
call FloatPrint
finit
fld R$val1
fimul D$val3
fstp R$val1
mov eax, val1
call FloatPrint
call 'Kernel32.ExitProcess' &NULL
Proc FloatPrint:
call 'MSVCRT.sprintf' buffer formatf D$eax D$eax+4
call 'USER32.MessageBoxA' &NULL buffer Title &MB_SYSTEMMODAL__&MB_OK
EndP
You can find more Win32 asm code at my Geocities webpage.
http://www.geocities.com/yeohhs
Best Regards,
Yeoh
--
zifeer
May 14th, 2006, 09:03 AM
Thanx for that code, but I tried to compile it using MASM615 (ofcourse I made the needed changes for the data and other instructions) but it didn't work. The compiler didn't recognize the FloatPrint instructions. I need to do this in MASM615, I can't use another compiler for this project. Does anybody here know how to work with MASM?
Thank you for all your help.
yeohhs
May 14th, 2006, 11:20 PM
There is a forum for MASM users here:
http://www.masmforum.com/simple/index.php
Best Regards,
Yeoh
zifeer
May 15th, 2006, 12:05 PM
Thanx for the link :D
nolxev
May 15th, 2006, 03:43 PM
finit
finit
Why these two calls to FINIT ? The FPU is enabled by OS. Is it a compiler stuff that require them ? I think there is no need to manually enable FPU.
yeohhs
May 15th, 2006, 09:39 PM
For information about finit and how it is used in asm code, please see this:
http://www.website.masmforum.com/tutorials/fptute/fpuchap3.htm#finit
Best Regards,
Yeoh
--
nolxev
May 16th, 2006, 08:29 AM
I forget that FINIT also reset all the registers and flags to their default values, I was only saying that FPU is already enabled when you write code.
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.