flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > how to eval a expression before the Match?

Author
Thread Post new topic Reply to topic
lilainst



Joined: 29 Jul 2004
Posts: 11
lilainst
For example, the following code never got matched, since the 'new' was calculated after the 'match':

Code:
rept 8 counter {
        new = counter * 4
        match =4, new {display "match it"}
}
    



Is it possible to do some match which depends on the previous expression? Thanks.
Post 05 Mar 2006, 08:35
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
If you need calculations, use assembler, not preprocessor:
Code:
repeat 8
  new = % * 4
  if new=4
    display "..."
  end if
end repeat    
Post 05 Mar 2006, 11:40
View user's profile Send private message Visit poster's website Reply with quote
lilainst



Joined: 29 Jul 2004
Posts: 11
lilainst
In order not to bother everyone here, I didn't post all my intention in the first post. Sorry.

Actually, I wanna write a Macroinstruction to display values of some constants. Of course, there's an example in manual pages which displays 32bit value, however, I intend to write a macro which could display the value of constant in spite of its length. I wrote the following code:
Code:
macro   output value {
        display "0x"
        repeat 16  ; 64bit number
                tmp = (value shr ((% - 1) * 4))
                nybble = tmp and 0xf
                if tmp <> 0
                        if nybble > 9
                                char = 'A' + nybble - 9 - 1
                        else
                                char = '0' + nybble
                        end if
                        display char
                end if
        end repeat
}

output  0xabcdef1234567890
    


The problem is "output" macro will display the value in reverse order. As I remembered there's an example of 'append' macro in the manual, which could help build macro args, I change the code to :
Code:
list equ
macro append item
{
        match   any, list \{ list equ list, item\}
        match   , list  \{list equ item\}
}

macro   display_nybble [arg]
{
        reverse display arg
}


macro   output value {
        display "0x"
        repeat 16   ; 64bit number
                tmp = (value shr ((% - 1) * 4))
                nybble = tmp and 0xf
                if tmp <> 0
                        if nybble > 9
                                char = 'A' + nybble - 9 - 1
                        else
                                char = '0' + nybble
                        end if
                         ; append char to list
                        append char
                end if
        end repeat
}

output  0xabcdef1234567890

match params, list {display_nybble params}
    

It doesn't work either, cause the 'match' is processed before the calculations. Should I think in another way?
Thanks in advance.
Post 05 Mar 2006, 23:20
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
The outputting code is written in the assembler's language, while the "macro" and "match" are the things of preprocessor - you cannot mix those two worlds in this way.
You should instead modify the assembler's algorithm to produce the digits in the reverse order. Replacing (% - 1) by (16 - %) should be enough in this case.
Post 05 Mar 2006, 23:27
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.