flat assembler
Message board for the users of flat assembler.

Index > DOS > floating point arithmatics

Author
Thread Post new topic Reply to topic
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 24 May 2015, 04:17
hello,i'm trying learn addition of 2 floating point numbers with the code(attached) bellow.when adding same numbers two times they give different results(well results are in other way round and it is not the problem)
can someone please explain me why two results (addition1 and addition2 in the code)for same numbers? Sad


Description:
Download
Filename: float1b.ASM
Filesize: 1.72 KB
Downloaded: 740 Time(s)

Post 24 May 2015, 04:17
View user's profile Send private message Send e-mail Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 24 May 2015, 18:03
Your text buffers are broken. Wink
Code:
; String buffers should be 32 digits + terminating character
num1    db 33 dup (0)
num2    db 33 dup (0)
    


Additionally, there's more than one way to add two floating point numbers...
Code:
finit
fld   dword [float1]
fadd  dword [float2]
fstp  dword [float3]
    
Post 24 May 2015, 18:03
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 24 May 2015, 18:22
Thank you very much
please can you explain more?
I thought with loop of stosb will make a string(text buffer) for 32times which starting from num1 or num2 and add 24h to the end of it with last stosb.
Post 24 May 2015, 18:22
View user's profile Send private message Send e-mail Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 24 May 2015, 18:26
by the way your solution worked like a charm.thanks again
Post 24 May 2015, 18:26
View user's profile Send private message Send e-mail Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 24 May 2015, 18:31
The problem is that you made your text buffers only one byte large. The first binary value that is printed out is correct, but when you created the string in buffer num1, you ended up overwriting the floating point constants. Therefore, the second time you tried to add the numbers together, float4 and float5 weren't equal to 9.45 and 5.22 anymore. They were destroyed.

If you had put your float constants before your text buffers, it would've worked correctly as well. Or... you could expand num1 and num2 to cover 33 bytes each, like I suggested above.
Post 24 May 2015, 18:31
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 24 May 2015, 18:46
many many thanks Trinitek. Very Happy Very Happy
Post 24 May 2015, 18:46
View user's profile Send private message Send e-mail Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 24 May 2015, 18:52
No problem!
Post 24 May 2015, 18:52
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.