flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Why Fasmw 1.73 not do (2-1)f

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1718
Roman 17 Oct 2023, 08:31
I thinking Fasmw 1.73 do this, but not Sad
Code:
mov eax, (2-1)  ;ok

mov eax, (2-1)#f ;not error
mov eax, (2-1)f  ;not error
mov eax, (2-1)#.#0 ;not error
    


Maybe struc help me do this:

23,24,15
I want get this: dd 23f,(23+24)f,(23+24+15)f
Post 17 Oct 2023, 08:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20203
Location: In your JS exploiting you and your system
revolution 17 Oct 2023, 12:04
You can make a macro to construct floats from integers.

Or you can store integers in the source and load them at runtime into the float registers and let the hardware do the conversion.
Post 17 Oct 2023, 12:04
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: 20203
Location: In your JS exploiting you and your system
revolution 17 Oct 2023, 12:59
I tried float and double but it can't exceed 2^31 for the value.
Code:
struc float value {
        rept 1 v:value \{
                dd v\#f
        \}
}
struc double value {
        rept 1 v:value \{
                dq v\#f
        \}
}
a float 4 - 3
b float 23 + 34
c double 1999999999 ; can't use >= 2^31
d double -1999999999 ; can't use < -2^31    
Post 17 Oct 2023, 12:59
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 795
Location: Russian Federation, Sochi
ProMiNick 17 Oct 2023, 13:21
Code:
macro dsingle [val] { dd ($7F+bsr ((val) or 1)) shl 23 + (((val) shr (bsr ((val) or 1)-23)) and not $FF800000) }
macro ddouble [val] { dq ($3FF+bsr ((val) or 1)) shl 52 + (((val) shr (bsr ((val) or 1)-52)) and not $FFF0000000000000) }
macro dtbyte [val] {
dq ((val) shr ((bsr ((val) or 1))-63))
dw ($3FFF+bsr ((val) or 1))  }

dsingle 1,1+2,(6+2)*4 shl 1;dd 1f,3f,64f
ddouble 1,1+2,(6+2)*4 shl 1;dq 1f,3f,64f
dtbyte 1,1+2,(6+2)*4 shl 1;dt 1f,3f,64f     

limitation of current computation: only positive expression of integer operands with integer operations.

I more like revolution variant then mine.

getting sign addend could be reached via "(val) and $80000000" for single
via "(val) and $8000000000000000" for double
via "((val) and $8000000000000000) shr 24" for doubleext
but for counting negates instead of val in rest of calculation must be absolute value of val (no idea how to construct)
for zero handling could be added multiplier (1-1 shl ((val) and -(val)))


Last edited by ProMiNick on 17 Oct 2023, 13:43; edited 1 time in total
Post 17 Oct 2023, 13:21
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1718
Roman 17 Oct 2023, 13:34
Thanks revolution and ProMiNick
Post 17 Oct 2023, 13:34
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 795
Location: Russian Federation, Sochi
ProMiNick 17 Oct 2023, 14:53
Code:
macro dsingle [val] { dd (1-1 shl ((val) or -(val)))*\
                        ( \
                          ((val) and $80000000) or \
                          (($7F+bsr (((val)*(1-((val) and $80000000) shr 30)) or 1) ) shl 23) or \
                          ((((val)*(1-((val) and $80000000) shr 30)) shr ((bsr (((val)*(1-((val) and $80000000) shr 30))or 1))-23)) and not $FF800000)\
                         ) }
macro ddouble [val] { dq (1-1 shl ((val) or -(val)))*\
                        ( \
                          ((val) and $8000000000000000) or \
                          (($3FF+bsr (((val)*(1-((val) and $8000000000000000) shr 62)) or 1)) shl 52) or \
                          ((((val)*(1-((val) and $8000000000000000) shr 62)) shr (bsr (((val)*(1-((val) and $8000000000000000) shr 62)) or 1)-52)) and not $FFF0000000000000)\
                         ) }
macro dtbyte [val] {
dq (1-1 shl ((val) or -(val)))*((((val)*(1-((val) and $8000000000000000) shr 62)) shr ((bsr (((val)*(1-((val) and $8000000000000000) shr 62)) or 1))-63)))
dw (1-1 shl ((val) or -(val)))*((((val) and $8000000000000000) shr 24 + $3FFF+bsr (((val)*(1-((val) and $8000000000000000) shr 62)) or 1)))  }     

no limits variant
where
multiplier zerotest = (1-1 shl ((val) or -(val)))
dword absolute of value = ((val)*(1-((val) and $80000000) shr 30))
qword absolute of value = ((val)*(1-((val) and $8000000000000000) shr 62))
Post 17 Oct 2023, 14:53
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 795
Location: Russian Federation, Sochi
ProMiNick 17 Oct 2023, 20:05
final:
Code:
macro dsingle [val] { dd (1-1 shl ((val) or -(val)))*\
                        ( \
                          ((val) shr 64 shl 31) or \
                          (($7F+bsr (((val)*(val) shr 64 or 1) or 1) ) shl 23) or \
                          ((((val)*(val) shr 64 or 1) shr ((bsr (((val)*(val) shr 64 or 1)or 1))-23)) and not $FF800000)\
                         ) }
macro ddouble [val] { dq (1-1 shl ((val) or -(val)))*\
                        ( \
                          ((val) shr 64 shl 63) or \
                          (($3FF+bsr (((val)*(val) shr 64 or 1) or 1)) shl 52) or \
                          ((((val)*(val) shr 64 or 1) shr (bsr (((val)*(val) shr 64 or 1) or 1)-52)) and not $FFF0000000000000)\
                         ) }
macro dtbyte [val] {
dq (1-1 shl ((val) or -(val)))*((((val)*(val) shr 64 or 1) shr ((bsr (((val)*(val) shr 64 or 1) or 1))-63)))
dw (1-1 shl ((val) or -(val)))*(((val) shr 64 and $8000 + $3FFF+bsr (((val)*(val) shr 64 or 1) or 1)))  }     

allow val within range of all possible fasm integers from (-1) shl 64 to +1 shl 63
Post 17 Oct 2023, 20:05
View user's profile Send private message Send e-mail 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.