flat assembler
Message board for the users of flat assembler.

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

Joined: 21 Apr 2012
Posts: 1618
Roman 17 Oct 2023, 08:31
I thinking Fasmw 1.73 do this, but not
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
17 Oct 2023, 08:31
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 19871
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.
17 Oct 2023, 12:04
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 19871
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
17 Oct 2023, 12:59
ProMiNick

Joined: 24 Mar 2012
Posts: 770
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
17 Oct 2023, 13:21
Roman

Joined: 21 Apr 2012
Posts: 1618
Roman 17 Oct 2023, 13:34
Thanks revolution and ProMiNick
17 Oct 2023, 13:34
ProMiNick

Joined: 24 Mar 2012
Posts: 770
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))
17 Oct 2023, 14:53
ProMiNick

Joined: 24 Mar 2012
Posts: 770
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
17 Oct 2023, 20:05
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum