flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Use eqtype with numerical constants

Author
Thread Post new topic Reply to topic
rCX



Joined: 29 Jul 2007
Posts: 176
Location: Maryland, USA
rCX 31 Oct 2026, 18:18
Is there a way to use eqtype with numerical constants. It seems to understand immediate constants but not numerical constants
Code:
macro testMacro var
{
    if var eqtype 1.1
        display "This is a float",13,10
    else
        display "This is not a float",13,10
    end if
}

x = 3.14
y equ 3.14
testMacro 3.14   ; Displays "This is a float"
testMacro x      ; Displays "This is not a float"
testMacro y      ;  Displays "This is a float"
    
Post 31 Oct 2026, 18:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21194
Location: In your JS exploiting you and your system
revolution 31 Oct 2026, 20:06
Once 3.14 is stored in x the assembler now considers it just an ordinary 65-bit value. There isn't a way to undo that because the assembler doesn't have any way to know if a value is intended to be interpreted as a float.
Code:
macro testMacro var
{
    if var eqtype 1.1
        display "This is a float",13,10
    else if var eqtype 0
        display "This is an integer",13,10
    else
        display "This is not a number",13,10
    end if
}

x = 3.14
testMacro x      ; Displays "This is an integer"    


Last edited by revolution on 31 Oct 2026, 22:41; edited 1 time in total
Post 31 Oct 2026, 20:06
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8571
Location: Kraków, Poland
Tomasz Grysztar 31 Oct 2026, 20:55
Yes, as said above, numeric variable/constant in fasm 1.x can only be an integer type (with some variable terms added, if it's an address with registers or relocatable bases), and upon the value assignment a floating-point value is converted into a binary representation and stored as an integer.
In other words, this:
Code:
x = 3.14    
has the same effect as this:
Code:
x = 40091EB851EB851Fh    

I've been aware that this limitation is often contrary to expectations, which is why I designed fasmg to allow variables containing floating-point or string values and marked as such (and also explicit conversions of types). Because of that, fasmg's EQTYPE has been reworked to evaluate expressions and compare types of the results.

Therefore with fasm2 your example would work as you expected (after updating the macro to fasmg's "end macro" syntax).

On the other hand, this made fasmg's EQTYPE not accept a freeform syntax, which would need to be filtered out with MATCH first. With fasm 1 you can compare sequences of tokens that can be almost anything:
Code:
macro testMacro seq&
{
    if seq eqtype 1f::'',[0]
        display "This is of type float::'str',[addr]",13,10
    else
        display "This is not",13,10
    end if
}

testMacro 3.14::'Hello!',[ebx]    
Which is why the EQTYPE of fasm 1.x is better characterized as comparing the lexical structure of text, not the types of values. A variable is not evaluated, it is seen as a numeric expression and considered the same type as any other numeric expression. The symbolic variables behave differently, because they are replaced during the preprocessing.
Post 31 Oct 2026, 20:55
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: 21194
Location: In your JS exploiting you and your system
revolution 31 Oct 2026, 22:49
Code:
$ cat test.asm 
if 3.14 = 40091EB851EB851Fh
        display 'same thing',13,10
end if

$ fasm test.asm 
flat assembler  version 1.73.31  (16384 kilobytes memory)
same thing
1 passes, 0 bytes.    
Post 31 Oct 2026, 22:49
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-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.