Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Assembly (http://www.programmingforums.org/forum20.html)
-   -   how to print floating point numbers (http://www.programmingforums.org/showthread.php?t=9407)

eax Apr 17th, 2006 2:00 PM

how to print floating point numbers
 
Programs computes the roots of Quadratic equations: Ax^2+Bx+C=0,it doesnot print the fractional part of roots.

How to print fractional part ?

finit
fstcw controlWd
or controlWd,0000110000000000b
fldcw controlWd

output prompt1
output prompt2
input string,40
atod string
mov A,eax



output prompt3
input string,40
atod string
mov B,eax


output prompt4
input string,40
atod string
mov C1,eax


fild C1 ;value of C in ST0
fild A ;value of A in ST1
fmul ;A*C and in ST0
fild no ;4 in ST0
fmul ;4*A*C and in ST0
fild B ;B in ST0
fild B ;B in ST1
fmul ;B*B in ST0
fsubr ;B*B - ( 4*A*C) and in ST0
fsqrt ;Determinant( D ) = SQRT( B^2-4AC) and in ST0
fist no3 ;store D
mov eax,no3 ;store D in eax
fild B ;B in ST0
fchs ;-B in ST0
fsubr ;-B-D in ST0
fild no4 ;2 in ST0
fild A ;A in ST0
fmul ;2*A
fdiv ;-B-D/2*A
fist no5 ;store first root
mov ebx,no5 ;store first root in ebx
fild no3 ;D in ST0
fild B
fchs
fadd
fild no4
fild A
fmul
fdiv
fst no10
fist no7
mov ecx,no7



dtoa no6,ebx
output print2


dtoa no9,ecx
output print3

DaWei Apr 17th, 2006 2:50 PM

EAX, you have 14 posts. One would presume that you have read the forum's rules and "How to Post..." threads just as a courtesy to your fellow members. To fit in, donchano. Read them again, looking out for the part that mentions using 'code tags.'

eax Apr 17th, 2006 5:47 PM

How to print floting point numbers ?
 
Thanks, DaWei for pointing it out .

This Program computes the roots of Quadratic equations: Ax^2+Bx+C=0,it doesnot print the fractional part of roots.

How to print fractional part ?

:

finit
fstcw controlWd
or controlWd,0000110000000000b
fldcw controlWd


output prompt1
output prompt2
input string,40
atod string
mov A,eax


output prompt3
input string,40
atod string
mov B,eax


output prompt4
input string,40
atod string
mov C1,eax


fild C1                              ;value of C in ST0
fild A                              ;value of A in ST1
fmul                                ;A*C and in ST0
fild no                              ;4 in ST0
fmul                                ;4*A*C and in ST0
fild B                              ;B in ST0
fild B                              ;B in ST1
fmul                                ;B*B in ST0
fsubr                                ;B*B - ( 4*A*C) and in ST0
fsqrt                                ;Determinant( D ) = SQRT( B^2-4AC) and in ST0
fist no3                            ;store D
mov eax,no3                          ;store D in eax
fild B                              ;B in ST0
fchs                                ;-B in ST0
fsubr                              ;-B-D in ST0
fild no4                            ;2 in ST0
fild A                              ;A in ST0
fmul                                ;2*A
fdiv                                ;-B-D/2*A
fist no5                            ;store first root
mov ebx,no5                        ;store first root in ebx
fild no3                            ;D in ST0
fild B
fchs
fadd
fild no4
fild A
fmul
fdiv
fst no10
fist no7
mov ecx,no7



dtoa no6,ebx
output print2


dtoa no9,ecx
output print3


DaWei Apr 17th, 2006 6:11 PM

It's probably just my age and inactivity showing, but your code looks strange to me. What assembler are you using, and are there macros floating about that I can't see?

eax Apr 17th, 2006 6:18 PM

I am using ML assembler from MASM 6.1 , i am not using any macros.
I am just using FPU 8 registers and only Floating point instructions to accomplish the task.

DaWei Apr 17th, 2006 7:10 PM

Okay, I'm going to unashamedly admit that I never saw a MASM with dtoa and output instructions. I'm going to leave you to the tender mercies of someone else. I suspect the conversion and output, though.


All times are GMT -5. The time now is 6:41 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC