flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > "match" confuses me - preprocessor conditional

Author
Thread Post new topic Reply to topic
SPTH



Joined: 24 Jul 2004
Posts: 91
SPTH 22 Apr 2011, 05:58
Hey,
So, I just learned (after increadible long bug searching), that IF...ELSE...END is an assembler-conditional command.

I had this code

Code:
macro PerformBug
{
    @myList.count EQU 0
    display '@myList.count: ', @myList.count+'0',13,10

    if 0=1
        display 'In the forbidden if-branch',13,10
        @myList
    end if

    display 13,10,'@myList.count: ', @myList.count+'0'
}

@myList.count EQU 0
macro @myList
{
    display 'In the macro that should never be called'
    rept 1 n:@myList.count+1 \{ @myList.count equ n \}

}

PerformBug 
...
OutPut:
@myList.count: 0
@myList.count: 1
    


OK, I want this IF to work for the preprocessor too, such that my output would be:

Code:
@myList.count: 0
@myList.count: 0
    


I tried it with match, but I has some very odd behaviour:

Code:
    match =0, 0 ; TRUE  - as expected
    match =0, 1 ; FALSE - as expected
    match =145, 0x91 ; FALSE - NOT EXPECTED
    match =145, (144+1) ; FALSE - NOT EXPECTED
    


Why do they not match?

In the end I want something to compare like this:
Code:
RndSymbol = %t AND 0xFFFF'FFFF
macro NewRndSymbol
{
    RndSymbol = ((RndSymbol*214013+2531011) AND 0xFFFF'FFFF)
}  

macro DoItHere
{
    RR EQU RndSymbol MOD 5
    rept 10 c
    \{
        match =c, RR \\{ ... \\}
    \}
}

DoItHere
    


I would prefere to find some good explanations about it - would like to use the whole power of that command(s). Is there some good description of example about match (i've serached in this board and in fasm directory, but most things confused me alot. And in the Programmers guide there is just a 1page text about conditional preprocessing)?

Thanks alot!


PS: How can I find out the datatype of an object (like: is "c equ 0x0" a byte, word, dword, qword? what about % or %t? ...) and are there ways to typecast for comparing it with match/if?
Post 22 Apr 2011, 05:58
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 22 Apr 2011, 06:56
Match works with symbols, not with numbers.
Read carefully the documentation, examples and do your own tests.
Post 22 Apr 2011, 06:56
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 22 Apr 2011, 08:08
Here is something I once wrote to explain a bit the things from the manual: http://board.flatassembler.net/topic.php?p=34035#34035
Post 22 Apr 2011, 08:08
View user's profile Send private message Visit poster's website Reply with quote
SPTH



Joined: 24 Jul 2004
Posts: 91
SPTH 22 Apr 2011, 19:11
Thank you Tomasz, that gave me some new insights. I read that the preprocessor is something like PHP which generates the HTML - interesting.

I thought I can simulate an IF...END IF in preprocessor-stage with MATCH, but it seems thats not possible.

So two questions now:

1) Is there a possibility to make an IF condition...END IF block, which will only be called by the preprocessor if condition is TRUE?

Such that this code:

Code:
TESTVALUE EQU 0

macro NEVERCALLED
{
    TESTVALUE EQU 1
}

IF 1=0
    NEVERCALLED
END IF

display TESTVALUE+'0'    


Will display 0 instead of 1.



2.) Is there a possibility that one can see the generated code AFTER the preprocessor, before the assembler? This would be very useful for debugging and understanding it preprocessor vs assembler better.
Post 22 Apr 2011, 19:11
View user's profile Send private message Reply with quote
SPTH



Joined: 24 Jul 2004
Posts: 91
SPTH 23 Apr 2011, 23:07
OK, I took JohnFound's advice and read all documents again. Now I understand what my problem was:
I wanted to create a list randomly and use that list for conditional code later. That means I totally mixed preprocessor and control directive.

When I finally understood it, I found a solution to my problem, by creating an analogon to a list in control directive (by saving the list-values in multiple numerical variables) - this works now.

Thanks to both of you for all the help! :)
Post 23 Apr 2011, 23:07
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.