flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Little idea for match directive

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19874
Location: In your JS exploiting you and your system
revolution 22 Apr 2008, 14:48
AsmER wrote:
those macros are really complex...
Yes, it is one of the biggest stumbling blocks people seem to have with fasm. The separation of the preprocessor and assembler forces one to write code in a particular way when dealing with the macros. Some things come out nicely and some other things come out weirdly.
Post 22 Apr 2008, 14:48
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER 22 Apr 2008, 15:45
OMG I have been trying to get this to work up untill now, and I just cant take it no more :/

Code:
_global@label equ
macro   label [args*]
{
common
        match name rest, args
        \{
                virtual at 0
                        db \`name
                        load _firstb@label byte from 0
                end virtual
                if _firstb@label eq .
                        public _global@label # name
                else
                        public name
                end if
        \}
        label args
}
    

I ve got this piece of code. all I want it to do is:
Code:
label Start
; to generate:
; public Start
; label Start

label .Sub_Label
; to generate:
; public Start.Sub_Label
; label .Sub_Label

; and so on
    

It just dont want to do what its told. I have been trying sticking 'match' directive in, putting '\' in possible places and nothink works...
after each check i made with fasmpre.exe following
Code:
display _firstb@label
if _firstb@label eq .
...
    

displays dot (.) like it should but next line on 'if' command it equals _firstb@label not stupid dot.
Please help me out before I get a heart attack Wink
Seriously... gimme a decent documentation just for macros
Quote:

...To overcome
this problem, the escaping of symbols inside macroinstruction can be used.
This is done by placing one or more backslashes in front of any other symbol
(even the special character)....

This for example, didnt make me think that i HAVE TO use it with all the symbols etc etc (thought its for nesting macros but for '{' and '}' really)
Thats all for me and macros for at least good few weeks Neutral

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


Joined: 24 Aug 2004
Posts: 19874
Location: In your JS exploiting you and your system
revolution 22 Apr 2008, 16:06
You have to escape the hash (#) also. Try this:
Code:
_global@label equ
macro   label [args*]
{
common
        match name rest, args
        \{
                virtual at 0
                        db \`name
                        load _firstb@label byte from 0
                end virtual
                if _firstb@label = '.'
                        public _global@label \# name
                else
                        public name
                end if
        \}
        label args
}    
Post 22 Apr 2008, 16:06
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: 19874
Location: In your JS exploiting you and your system
revolution 22 Apr 2008, 16:21
To make it clear and pre-empt a few upcoming problems, you have to escape all preprocessor symbols and directives properly. That is:

common
forward
reverse
local
`
#
}


{ (is optional for readability only)

The number of backslashes determines the level at which the symbol/directive will be processed. If you have no backslashes then it is processed by the outer layer, 1 backslash is processed by the second layer, and so on.
Post 22 Apr 2008, 16:21
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER 22 Apr 2008, 17:01
Ok got it to work finally
Code:
_global@label equ
macro   label [args*]
{
common
        _state@label equ 0
        match name rest, args
        \{
                virtual at 0
                        db \`name
                        load _firstb@label byte from 0
                end virtual
                if _firstb@label = '.'
                        match gname lname, _global@label name ;another match to connect 2 strings in %C style (beginning of post)
                        \\{
                                public gname \\# lname
                                _state@label equ 1 ; set state to changed
                        \\}
                        match =0, _state@label ; if match occurs: there was sub label, but no global label before it
                        \\{
                                public name
                                _state@label equ 1 ; set state to changed
                        \\}
                else
                        public name
                        match =0, _state@label ; check state with 'match' or wont work due to equ preprocessed at preprocessor state and 'else' at assembly time
                        \\{
                                _global@label equ name
                        \\}
                end if
        \}
        label args
}
    


I will really, really and I mean REALLY try to avoid writing macros which consist of items that get interpreted at different stages (and which need to interact with one another) end of day I guess im not that dumb after all - still dont know if i like macros more right now...

revolution - thx for further explanation on '\' symbol

Teamwork Smile

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


Joined: 24 Aug 2004
Posts: 19874
Location: In your JS exploiting you and your system
revolution 22 Apr 2008, 17:14
I think it won't give what you expect. Look at it from the preprocessor point-of-view by stripping out all the assembler code
Code:
_global@label equ
macro   label [args*]
{
common
        _state@label equ 0
        match name rest, args
        \{
          match gname lname, _global@label name \\{ _state@label equ 1 \\};never matches
          match =0, _state@label \\{ _state@label equ 1 \\}            ;always matches
          match =0, _state@label \\{ _global@label equ name \\}                ;never matches
        \}
}    
Post 22 Apr 2008, 17:14
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: 19874
Location: In your JS exploiting you and your system
revolution 22 Apr 2008, 17:29
Before you drive yourself barmy with this, I think you can't solve it with the current fasm version. I suggest you just simply use two macros, one for setting the global label and another for the subordinate labels.
Post 22 Apr 2008, 17:29
View user's profile Send private message Visit poster's website Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER 22 Apr 2008, 19:49
I found out that the macro doesnt do the job after few nimutes since posting, but as you already said its wrong I just left it as it was.
As for the matter whenever you can make this macro to work simple answer: NO Sad and the answer wont change unless we can chceck presence of dot in label's name without using assembly stage directives (I was making myself sure for last few hours haha)
That is it. We need to wait for my =Equate[indx:len] or your irpc, split, find, search or extract Wink

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 22 Apr 2008, 19:49
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 09 May 2008, 19:56
I once suggested the macro language be replaced with a strip-down version of JavaScript.

Something like like this would be much easier to pick up and use effectively. Less learning intricacies and more using.
Code:
<%
var TEST_EQU = ".lbl";
var LAST_EQU = "";
var X_INC = 0;

function nextLbl(){
LAST_EQU = TEST_EQU + X_INC;
document.write(LAST_EQU + ":");
 X_INC++; 
}
%>

MOV ecx,-1
<% nextLbl() %>
loopz <%=LAST_EQU%>
MOV ecx,-1
<% nextLbl(); %>
loopz <% LAST_EQU %>
    

Would process to
Code:
MOV ecx,-1
.lbl0:
loopz .lbl0
MOV ecx.-1
.lbl1:
loopz .lbl1
    
Post 09 May 2008, 19:56
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.