Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 17th, 2006, 2:00 PM   #1
eax
Newbie
 
eax's Avatar
 
Join Date: Mar 2006
Posts: 17
Rep Power: 0 eax is on a distinguished road
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
eax is offline   Reply With Quote
Old Apr 17th, 2006, 2:50 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.'
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 17th, 2006, 5:47 PM   #3
eax
Newbie
 
eax's Avatar
 
Join Date: Mar 2006
Posts: 17
Rep Power: 0 eax is on a distinguished road
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
eax is offline   Reply With Quote
Old Apr 17th, 2006, 6:11 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 17th, 2006, 6:18 PM   #5
eax
Newbie
 
eax's Avatar
 
Join Date: Mar 2006
Posts: 17
Rep Power: 0 eax is on a distinguished road
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.
eax is offline   Reply With Quote
Old Apr 17th, 2006, 7:10 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:50 AM.

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