flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Little idea for match directive

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
I have been playing around with preprocessor & macros lately, and I have got an idea that could add more functionality to match directive. Instead talking about it for ages I'll just give an example (I have enough writing on BTEC National Diploma's reports and in my fasm programs Very Happy )
Code:
; Alright, thats how it is now
some_equ equ text+2
match =text+=2, some_equ
{
   display 'it worked',13,10
}
; Ok, thats simple. We have pattern and in this case text equate compred against the pattern. Now lets get to the point...
some_equ equ text
match =text[=0], some_equ[0]
{
   display 'it worked again...',13,10
}
; in the above match, pattern and symbols sequence match as well.
; And here is what i thought would be usefull:
some_equ equ text
match =t, =some_equ[0]
{
   display 'Atm, this aint workin...'
}
; where in such definition of match, the sequence compared against pattern would not be recognised as:
; =
; text
; [
; 0
; ]
; but instead, it would be:
; t
; which is the first letter(byte) of what the equate holds
    


At this point we could make way more advanced macros (so i belive). Ernn, lets give an example: we want a macro that will overload existing directive:
Code:
; The label macro, to add more functionality to labels. more precisely, allow us to create 'public' directives at same time x]
global_label@label_macro equ

macro label [args]
{
        state_label@label_macro equ 0 ;1: sub_label, 2: global label, 0: not processed
        match name rest, args
        \{
        ; Here is my idea for syntax. basically [b]=[/b] before symbolic name in sequence of symbols to be compared activates the feature.
                match =. ,  =name[0]
                \\{
                        ; We could find out what is inside
                        ; symbols, bit by bit. Where atm
                        ; we can not do it
                        state_label@label_macro equ 1
                        public  global_label@label_macro name
                \\}
                match =0, state_label@label_macro
                \\{
                        global_label@label_macro equ name
                        state_label@label_macro equ 2
                        public name
                \\}
        \}
        match =0 name ,  state_label@label_macro args
        \{
                match =. , =name[0]
                \\{
                        ; We could find out what is inside
                        ; symbols, bit by bit. Where atm
                        ; we can not do it
                        state_label@label_macro equ 2
                        public  global_label@label_macro name
                \\}
                match =0, state_label@label_macro
                \\{
                        global_label@label_macro equ name
                        public name
                \\}
        \}
        label args
}
    

It should be noted that public directives would not work even if the syntax would be recognised right by fasm....
In case of following code:
Code:
label global_label
label .sub_label
    

public declaration would be:
Code:
public   global_label .sub_label
    

note space between global_label & .sub_label
so I guess that another symbol like: %C or whatever, which in equ definitions would remove spaces from surrounding it text, numbers etc would be nice to see...
Code:
my_equ1        equ        SomeText
my_equ2        equ        OtherText
my_new_equ     equ        my_equ1 %C my_equ2
    

Resulting with:
my_new_equ equate containing: SomeTextOtherText (instead of "SomeText OtherText")

OK, thats all Wink
I have no expections or whatsoever. This is simply an idea I got that could make our lifes a bit easier (and Tomasz Grysztar's a bit harder - unless he thinks that the idea is useles Very Happy)
Looking forward to hear what you think.

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 21 Apr 2008, 18:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17344
Location: In your JS exploiting you and your system
revolution
You can easily join string together with the hash (#), no need for %C.

What does this do? "match =. , =name[0]"
Post 21 Apr 2008, 18:46
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
@revolution
You are right that by using # we can join strings. Lets try
Code:
EQU1        equ        TEXT
EQU2        equ        CONNECTED
EQU3        equ        EQU1 # EQU2
; RESULT (EQU3):
; TEXT#CONNECTED
macro connect
{
        EQU3        equ        EQU1 # EQU2
}
connect
; RESULT (EQU3):
; EQU1EQU2
macro connect2
{
        EQU3        equ        `EQU1 # `EQU2
}   
; RESULT (EQU3):
; 'EQU1EQU2'
    

Well, it does work, but not the way I was talking about. Where:
Code:
EQU1        equ        TEXT
EQU2        equ        CONNECTED
EQU3        equ        EQU1 %C EQU2
; RESULT (EQU3):
; TEXTCONNECTED
macro connect
{
        EQU3        equ        EQU1 %C EQU2
}
connect
; RESULT (EQU3):
; TEXTCONNECTED
    


As for:
Quote:

What does this do? "match =. , =name[0]"

Example:
Code:
TEST_EQU        equ        abcdef
match any, =TEST_EQU[0]
{
        ...
}
    

If Mr Grysztar would implement what I am talking about:
any would be matched to a
if instead of =TEST_EQU[0] we would write =TEST_EQU[1]
any would be matched to b
by writing =TEST_EQU[5] any would be equal to f

Thanks for your question and interest. Please ask all the questions you have, I'm happy to answer

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 21 Apr 2008, 19:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17344
Location: In your JS exploiting you and your system
revolution
With the "EQU3 equ EQU1 # EQU2" you just put it inside a match to do the text translation.
Code:
match a b,EQU1 EQU2 { EQU3 equ a#b }    
So you want byte selection with the "=X[0]" construct. Why not just make a new keyword like "selectb thechar,TEST,0" and you can also put it inside a match to do text translation if needed. You can do this in the assembler stage with virtual and load, do you have an example where you need to it done at the preprocessor stage?
Post 22 Apr 2008, 02:30
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
As for the %C and match matter I must admit that I was pretty confident that the # operator works the same way in macros and matches. However that is working the way I wanted, I still think that the %C (or any other, doing same thing) would simplify the source code (imagine a macro where you need loads of such string connecting operations... what will be easier to read? lets say 20 lines of XXX equ XX %C X, or 20 lines of: match a b, XX X \{ XXX equ a#b \} (optionally with more '\' characters depending on position)or 60 lines when I put it my style- match ..., { next line, ... next line, } next line. Surelly, in this case someone may say: why the heck do you put everything in separate lines? but then I may ask why some people put comments on every single line of code, use HLL structures etc? -thats just how I want it to look like. Our exaple is a very basic one, you should put attention that some macros may need way advanced and by that longer instructions).

Conserning the idea of completly new keyword (selectb, as you sugested) I have been thinking about such option, but again I decided that not using it would be simplier and more readable.
For my idea all you need to do is to add additional check on symbols being matched with the 'match' pattern. So:
Code:
TXT_EQU equ Something
index = 3
; ----- new generation match x] ------
match any, =TXT_EQU[index]
{
     ; 'any' is matched to 'e' letter which is on the offset specified
}

; ----- old school match -- -------------
match any, = TXT_EQU[index]
{
     ; 'any' is matched traditional way, therefore equals '=Something[3]'
}
    

Additional keyword, which I belive should work somehow like match (creating temporary names of matched symbols) would require construction like:
Code:
TXT_EQU equ Something
selectb char, TXT_EQU, 3
{
     match =e, char
     \{
          ; actual match goes here in traditional way, 'char' equals 'e' like before
     \}
}
    


As for question about whenever I need it at preprocesor or assembly stage:
- This is my idea how to make 'match' more useful and flexible. I know about using virtual, load and store but like vid said (and he seems to be very respected here) "thing about "`", "load" and "store". that is the ugly way." (@ http://board.flatassembler.net/topic.php?t=6577 I found this post today)
It realy got me to thinking about the new feature and actually it could be even more powerful. Let me visualize it:
Code:
TXT_EQU    equ   SOMETEXT
index = 2
length = 5
match any, =TXT_EQU[index:length]
{
     ; 'any' would be matched to 'METEX'
}
    

So the idea is to add indexing to set position of start and length to inform how many bytes we want.
I really know that it may be pain to code it (depends from how the code handling 'match' is wrote) but think about the power the directive will gain!
For example, look at the post I referenced to above. With such functionality it will be a really trivial task:
Code:
txt_e   equ  library.procedure
index = 0
repeat 0xFF ;say we only wanna test first 256 bytes
   match =. ,  =txt_e[index]
   {
      break
   }
   index = index + 1
end repeat
end_offset = 0
repeat 0xFF
   match =0, =txt_e[end_offset]
   {
      break
   }
   end_offset = end_offset + 1
end repeat
match lib proc, =txt_e[0:index-1] =txt_e[index+1:end_offset-index+1]
{
; check it out!
; 'lib' matched to 'library'
; 'proc' to 'procedure'
}
; Well in case of =XXX[X:XX] expression, something like 'END' would be cool too.
; We could avoid one 'repeat' loop & second match would be just: match lib proc, =txt_e[0:index-1] =txt_e[index+1:END-index+1]
; or artenatively to have 'END' mean that we want everything up to the end of data ;] so it would be even simplier then:
; match lib proc, =txt_e[0:index-1] =txt_e[index+1:END]
    


Thanks for reply. Of course there will be no such situation where everybody will be 100% happy, therefore I will leave the final and concluding word to Mr Grysztar as he knows what will be best for his assembler (if he notices the topic hehe).

[Damn, I'm sooo good at making ideas that are hard to realise Rolling Eyes Wink ]

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 22 Apr 2008, 11:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17344
Location: In your JS exploiting you and your system
revolution
A lot of your ideas mix the assembler stage and preprocessor stage.
  • 'repeat' is an assembler stage directive so you can't mix it with 'match'.
  • '=' is an assembler stage assignment so you can't mix it with 'match'.
  • 'equ' can be mixed with 'match', they are done at the same stage.
AsmER wrote:
Code:
; 'lib' matched to 'library'
; 'proc' to 'procedure'    
Where do you need to do this, do you have an example?
Post 22 Apr 2008, 11:52
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: 17344
Location: In your JS exploiting you and your system
revolution
You may be interested in this topic, it shows how the preprocessor can be used to do basic arithmetic and may also help you to see why the assembler and preprocessor can't be used in the way you suggest. You need a different solution.
Post 22 Apr 2008, 12:02
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
Quote:

Code:
; 'lib' matched to 'library'
; 'proc' to 'procedure'


Where do you need to do this, do you have an example?


You didnt read my post carefully, did you? Rolling Eyes
anyways, there you go:
http://board.flatassembler.net/topic.php?t=6577
first post in the topic? (even that it doesnt points at it directly)

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 22 Apr 2008, 12:26
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17344
Location: In your JS exploiting you and your system
revolution
I saw the link but what I don't see is where you need to do this? MichaelH's example is solvable by simply putting in a colon (:) instead of a dot (.)
Post 22 Apr 2008, 12:36
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
Yeah, the example with a . was showing how to make one's life harder Very Happy
Since I have forgoten that 'repeat' and 'match' have different priority (or shall I say: are not 'executed' at same stage) the idea doesnt seem that cool anymore (now we would need additional kind of repeat instruction working at preprocessor stage...) I guess the idea itself is pretty good but somehow impossible to realise at the current state of how fasm work (dont worry I'm not going to force Tomasz to rewrite entire code just to have this working (n_n) - i know when to give up Smile )

One way or another, I would still like to hear what fasm creator has to say about this matter - maybe he can think of something that will be a solution without need to change anything (or rather: that much :] )

Regards

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 22 Apr 2008, 12:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17344
Location: In your JS exploiting you and your system
revolution
Maybe a 'split', 'find', 'search' or 'extract' preprocessor directive?
Post 22 Apr 2008, 12:57
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
Whatsoever. From my experience the only way to get results you want, is to do things yourself... So as I said, there is idea- how its going to be implemented, I'm not bothered as long as it actually accomplish the task.

Btw, you know the solution with 'virtual' you sugested. I have been trying to see if it works for me, and I faced a problem.. as you definately have better knowledge of fasm macros maybe you could help?
I'm trying to get the first letter (yep, no more twisted ideas for today) of whats in equate. i thought that it would be simply to use virtual directive, define bytes string inside it and get first one using 'load'. But the problem is I'm not too sure how to make definition like:
match name rest, args
{
virtual at 0
db name ;< problem here to get 'name' surrounded by quotation marks
load my_var byte from 0
end virtual
...
}
Or am I doing it completly wrong? Tried ` operator but get 'name' instead of actual value of 'name' in between ' characters. Any idea to get 'label_name' when 'name' equals it?

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 22 Apr 2008, 13:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17344
Location: In your JS exploiting you and your system
revolution
Works for me:
Code:
match name rest, test_label_junk nothing
{
       virtual at 0
                db `name
            x=0
         while x < $
                      load my_var byte from x
                     display my_var
                      x=x+1
               end while
   end virtual
}    
Post 22 Apr 2008, 13:45
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
` operator has bigger priority than replacing equates. Do it like this:
Code:
match x, name {
  db `x
}
    
Post 22 Apr 2008, 13:48
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
sorry, i missed that you already have "match" there... next time use [code] tag around code Wink
Post 22 Apr 2008, 13:50
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17344
Location: In your JS exploiting you and your system
revolution
Maybe irpc would be suitable. We already have irp and irps so one more would be kind of nice.
Post 22 Apr 2008, 14:31
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
Thanks for help guys, but I get a little problem... (why there is always something goin wrong Rolling Eyes)
ok
Code:
test_label_junk equ .MY_LABEL DWORD
match name rest, test_label_junk
{
        virtual at 0
                db `name
                        load my_var byte from 0
        end virtual
        display my_var
}
; Pretty much revolution's example, just reading first byte as I wanted
    

Displays dot (.) in messages window
Code:
macro   label [args*]
{
        match name rest, args
        \{
                virtual at 0
                        db `name
                        load label.firstb byte from 0
                end virtual
                display label.firstb
        \}
}     
label .MY_LABEL DWORD
    

Displays n letter... Shocked
Why is second version working differently?

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 22 Apr 2008, 14:35
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17344
Location: In your JS exploiting you and your system
revolution
You have to "escape" the "`", that is like this
Code:
macro   label [args*]
{
        match name rest, args
        \{
                virtual at 0
                        db \`name  ;<-- backslash here
                        load label.firstb byte from 0
                end virtual
                display label.firstb
        \}
}     
label .MY_LABEL DWORD     
Post 22 Apr 2008, 14:39
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: 17344
Location: In your JS exploiting you and your system
revolution
Also, don't forget about 'common', 'forward' and 'reverse' in your macro.


Last edited by revolution on 22 Apr 2008, 16:25; edited 1 time in total
Post 22 Apr 2008, 14:40
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
those macros are really complex...
I didnt have as many problems to learn asm language itself (even masm syntax which is weird for some ppl)
Thank you for fast reply
Post 22 Apr 2008, 14:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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.