flat assembler
Message board for the users of flat assembler.

Index > Main > Question about float point expressions in fasm

Author
Thread Post new topic Reply to topic
binwalk



Joined: 04 Apr 2018
Posts: 2
binwalk 04 Apr 2018, 04:15
I want to encode float point value into instruction like:
Code:
mov eax, 1.0/2    

but it compiles error
Code:
error: extra characters on line.    

while
Code:
mov eax, 0.5    

it compiles success

likewise
Code:
dd 0.5     ;success
dd 1.0/2   ;error
dd 1/2      ;success but the value is round to 0
    

my question is
why float point numerical expressions are not allow in this way? and am i must hard code single values instead of numberical expression?
Post 04 Apr 2018, 04:15
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 04 Apr 2018, 05:20
I guess because operators in expression of istruction operands reserved only for integer manipulations. for me it is very convinient: avoiding float everywhere where it is possible it is good.

1st solution: Thou can extend such behavior with macros for all thour cases, but macros dosn`t operate floats natively, so thou`ll have to extract float components (sign,mantissa,fraction) and manipulate on them manually.

2nd solution: or thou could make macros for thour particular case
macro mov op1,op2 {
local ?f
match =float =1 =. =0 =/ =2,op2 \{
mov op1,0.5
?f equ \}
match =?f,?f \{ mov op1,op2 \}
}

macro dd [val] {
local ?f
match =float =1 =. =0 =/ =2,op2 \{
dd 0.5
?f equ \}
match =float =1 =/ =2,op2 \{
dd 0.5
?f equ \}
match =?f,?f \{ dd val \}
}

2nd solution will increase readability personaly for thou and keep compilation time still fast.
Post 04 Apr 2018, 05:20
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20355
Location: In your JS exploiting you and your system
revolution 04 Apr 2018, 05:47
binwalk wrote:
my question is
why float point numerical expressions are not allow in this way? and am i must hard code single values instead of numberical expression?
fasm doesn't support arbitrary expression evaluation for non-integer values. The only expression you can use is just a single number value.

Internally fasm uses a higher precision representation than the FPU supports, so if arbitrary expressions were to be supported then all the operators (+, -, * and /) would have to be coded manually. It is not impossible to do, of course, but it would require having enough need for it and then finding time to code it and test it.
Post 04 Apr 2018, 05:47
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 04 Apr 2018, 09:32
In fasm 1 floating point values can only be passed directly to the module that converts them to the binary representation of given size, and thus any computations on them are impossible. On the other hand fasmg has them as a one of the types of values that can be passed around and kept in variables, and there it is possible to evaluate expressions with them.
Post 04 Apr 2018, 09:32
View user's profile Send private message Visit poster's website Reply with quote
binwalk



Joined: 04 Apr 2018
Posts: 2
binwalk 10 Apr 2018, 09:01
ProMiNick wrote:
I guess because operators in expression of istruction operands reserved only for integer manipulations. for me it is very convinient: avoiding float everywhere where it is possible it is good.

1st solution: Thou can extend such behavior with macros for all thour cases, but macros dosn`t operate floats natively, so thou`ll have to extract float components (sign,mantissa,fraction) and manipulate on them manually.

2nd solution: or thou could make macros for thour particular case
macro mov op1,op2 {
local ?f
match =float =1 =. =0 =/ =2,op2 \{
mov op1,0.5
?f equ \}
match =?f,?f \{ mov op1,op2 \}
}

macro dd [val] {
local ?f
match =float =1 =. =0 =/ =2,op2 \{
dd 0.5
?f equ \}
match =float =1 =/ =2,op2 \{
dd 0.5
?f equ \}
match =?f,?f \{ dd val \}
}

2nd solution will increase readability personaly for thou and keep compilation time still fast.


Your solution is clear, but it is easy to code it instead of using macro for just this case , now I have to accept that avoiding to use float point in numerical expression where I code Cool
Post 10 Apr 2018, 09:01
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.