flat assembler
Message board for the users of flat assembler.

Index > Main > Why Fasm don`t add float numbers ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1849
Roman 29 Aug 2020, 08:37
Code:
mov dword [edx],11.6+5.6 ;Fasm get error
mov dword [edx+StrucName.code],11+5 ;ok
    


I try this but get error:
Code:
mov dword [edx+StrucName.code],11f+5f
    


Last edited by Roman on 29 Aug 2020, 08:44; edited 1 time in total
Post 29 Aug 2020, 08:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20453
Location: In your JS exploiting you and your system
revolution 29 Aug 2020, 08:43
What happens if you try this?
Code:
x = 4.2
y = 3.6
dd x   ; error: value out of range.
dd y   ; error: value out of range.
dd x+y ; error: value out of range.
dq x+y ; okay. But what value is stored?    
Post 29 Aug 2020, 08:43
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1849
Roman 29 Aug 2020, 08:52
I do this:
Code:
x = 0.5f
z = 0.5f
Floats dq x,z,x+z,0,0
    

IDA Pro show this:
Floats: dd 0,3FE00000h
dd 0,3FE00000h
dd 0,7FC00000h
dd 4 dup(0)
Post 29 Aug 2020, 08:52
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20453
Location: In your JS exploiting you and your system
revolution 29 Aug 2020, 08:56
Do you know how the float format is stored?
Post 29 Aug 2020, 08:56
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1849
Roman 29 Aug 2020, 08:58
Post 29 Aug 2020, 08:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20453
Location: In your JS exploiting you and your system
revolution 29 Aug 2020, 09:05
fasm doesn't have a float computation engine. So any arithmetic you try will come out wrong. See my example above. If you add 4.2 and 3.6 you get -4.116386638238323e-308
Post 29 Aug 2020, 09:05
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1849
Roman 29 Aug 2020, 09:05
Quote:

Do you know how the float format is stored?

Do you remember rept trick converted to float ?
rept 2 m:1 {dd -m\#.8 }
Post 29 Aug 2020, 09:05
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1849
Roman 29 Aug 2020, 09:07
Quote:

fasm doesn't have a float computation engine. So any arithmetic you try will come out wrong. See my example above. If you add 4.2 and 3.6 you get -4.116386638238323e-308

If convert text to float use sse(calculate 4.2+3.6) and convert result to text ?


Last edited by Roman on 29 Aug 2020, 09:10; edited 2 times in total
Post 29 Aug 2020, 09:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20453
Location: In your JS exploiting you and your system
revolution 29 Aug 2020, 09:07
fasm can convert text into floats. fasm can't then add those floats together because the format isn't a simple integer.
Post 29 Aug 2020, 09:07
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20453
Location: In your JS exploiting you and your system
revolution 29 Aug 2020, 09:08
Roman wrote:
If convert to float use sse(4.2+3.6) and convert to text ?
fasm only uses 386 opcodes. SSE isn't available.
Post 29 Aug 2020, 09:08
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1849
Roman 29 Aug 2020, 09:11
This is another reason keep write my fasm++

Quote:
fasm only uses 386 opcodes. SSE isn't available.

How about fasmg ?
Post 29 Aug 2020, 09:11
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 29 Aug 2020, 10:53
Roman wrote:
How about fasmg ?
fasmg does support floating-point computations. You can assemble the instruction from your sample as is:
Code:
include 'cpu/p6.inc'
use32

mov dword [edx],11.6+5.6    
PS. fasmg also uses only 386-compatible instructions in its core. One has nothing to do with the other.
Post 29 Aug 2020, 10:53
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 06 Sep 2020, 23:45
Tomasz, why doesn't it updated yet for few already old generations? Does some one still use 386-processors?
Post 06 Sep 2020, 23:45
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4075
Location: vpcmpistri
bitRAKE 07 Sep 2020, 03:57
There are x86 embedded systems that are 386, IIRC.

Newer instructions don't inherently provide a benefit.
Post 07 Sep 2020, 03:57
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 07 Sep 2020, 08:05
bitRAKE, 387,mmx,sse? Isn't it better to deal with float numbers?
Post 07 Sep 2020, 08:05
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20453
Location: In your JS exploiting you and your system
revolution 07 Sep 2020, 08:07
Overclick wrote:
... 387,mmx,sse? Isn't it better to deal with float numbers?
No. Loss of accuracy is a problem to consider.
Post 07 Sep 2020, 08:07
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.