flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Break out of forward or reverse

Author
Thread Post new topic Reply to topic
Syrasia



Joined: 25 Feb 2010
Posts: 11
Location: Saarland, Germany
Syrasia 08 Oct 2012, 08:59
Hello there,
I came back to fasm, since purebasic is not flexible enogth for me. And assembling is much more fun for me. Everthing is perfect until i hit this roads end: how can i break out of processing a reverse or forward block of a macro?!?
I need a macro with 2 times dinamic parameters, ie macro myShit arg1,arg2 arg3, splitter, arg4, arg5
frist forward should proces arg1 to 3
Now a common or so
Second reverse should proces arg4 and 5
Some common here now a reverse with and finishing forward with arg1 to 3
Do you get what i want to archive?
Seach was not helping meeee arg
help me and love you all

_________________
Back to fasm, the best
Post 08 Oct 2012, 08:59
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 08 Oct 2012, 09:43
IMO, the most clean solution would be to create multiple macros. Here's a simple example with splitter being the "||" characters:
Code:
macro forwardLoop [arg] {
  forward display `arg,13,10
}

macro reverseLoop [arg] {
  reverse display `arg,13,10
}

macro ohMy [params] {
 common match firstBatch||secondBatch,params \{
   forwardLoop firstBatch
   reverseLoop secondBatch
 \}
}


ohMy 1,2,3 || 4,5,6    
If you want to define a different splitter syntax, make sure what is the right syntax for it in the MATCH expression. The same example with different kind of splitter:
Code:
macro forwardLoop [arg] {
  forward display `arg,13,10
}

macro reverseLoop [arg] {
  reverse display `arg,13,10
}

macro ohMy [params] {
 common match firstBatch=,=@=,secondBatch,params \{
   forwardLoop firstBatch
   reverseLoop secondBatch
 \}
}



ohMy 1,2,3,@,4,5,6    


Last edited by Tomasz Grysztar on 08 Oct 2012, 09:45; edited 1 time in total
Post 08 Oct 2012, 09:43
View user's profile Send private message Visit poster's website Reply with quote
Syrasia



Joined: 25 Feb 2010
Posts: 11
Location: Saarland, Germany
Syrasia 08 Oct 2012, 10:01
Woha, exatly. Man the first one is just perfekt. Thanks a lot
Post 08 Oct 2012, 10:01
View user's profile Send private message Send e-mail Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 08 Oct 2012, 13:33
1,2,3 test,test Microphon Check...
increase readability,
Code:
macro ohMy [params] {
        define status 0
     match =0 direct rest,status params \{
         display \`direct,13,10
             irp i,rest\\{
                \direct
                    display \\`i,13,10
                        dd a#_beep      ;<---
                    display_hex 32,a#_beep
                      display 13,10
                       dd 0
                        display_hex 32,a#_boop
                      display 13,10
               \\}
  define status 1
     \}
    match =0,status \{
            \common
            display "common "
         irp i,params\\{
                      display_hex 32,$
                    display " "
                       label a\\#i           ;<--- 
                   display \\`i,13,10
                \\}
  \}
}
ohMy 15,16,_boop,<reverse 1,2,3>,<forward 5,6>,<reverse 11,12,13>,_beep,18,19    


Quote:

flat assembler version 1.69.34 (1048575 kilobytes memory)
common 004020B6 15
common 004020B6 16
common 004020B6 _boop
reverse
3
004020F6
004020B6
2
004020F6
004020B6
1
004020F6
004020B6
forward
5
004020F6
004020B6
6
004020F6
004020B6
reverse
13
004020F6
004020B6
12
004020F6
004020B6
11
004020F6
004020B6
common 004020F6 _beep
common 004020F6 18
common 004020F6 19
4 passes, 0.1 seconds, 2048 bytes.


Cheers, Very Happy

_________________
⠓⠕⠏⠉⠕⠙⠑
Post 08 Oct 2012, 13:33
View user's profile Send private message Visit poster's website Reply with quote
Syrasia



Joined: 25 Feb 2010
Posts: 11
Location: Saarland, Germany
Syrasia 16 Oct 2012, 18:57
Okay, the macro is working almost perfekt. Almost.
I would like to be able to let out parms,
ie ohMy ard1,word||
or this: ohMy ||arg
is thiy also posible (complex macros are welcome) Smile

_________________
Back to fasm, the best
Post 16 Oct 2012, 18:57
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 16 Oct 2012, 21:33
It may be simply extended this way:
Code:
macro forwardLoop [arg] {
  forward display `arg,13,10
}

macro reverseLoop [arg] {
  reverse display `arg,13,10
}

macro ohMy [params] {
 common match firstBatch||secondBatch,params \{
   forwardLoop firstBatch
   reverseLoop secondBatch
 \}
 match firstBatch||,params \{
   forwardLoop firstBatch
 \}
 match ||secondBatch,params \{
   reverseLoop secondBatch
 \}
}


ohMy 1,2,3 ||
ohMy || 4,5,6    
However this works under the assumption that matches are mutually exclusive. When matching kinds of expressions that may overlap (and thus multiple "match" blocks would get executed), you would need to introduce additional status variable to get an IF-ELSE behavior of "match":
Code:
macro forwardLoop [arg] {
  forward display `arg,13,10
}

macro reverseLoop [arg] {
  reverse display `arg,13,10
}

macro ohMy [params] {
 common local T
   match =T firstBatch||secondBatch,T params \{
     forwardLoop firstBatch
     reverseLoop secondBatch
     define T
   \}
   match =T firstBatch||,T params \{
     forwardLoop firstBatch
     define T
   \}
   match =T ||secondBatch,T params \{
     reverseLoop secondBatch
     define T
   \}
}


ohMy 1,2,3 ||
ohMy || 4,5,6    
Post 16 Oct 2012, 21:33
View user's profile Send private message Visit poster's website Reply with quote
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
yoshimitsu 16 Oct 2012, 21:36
Code:
macro forwardLoop [arg] {
  forward display `arg,13,10 
} 

macro reverseLoop [arg] { 
  reverse display `arg,13,10 
} 

macro ohMy [params] { 
 common done@ohMy equ
  match firstBatch||secondBatch,params \{
   forwardLoop firstBatch 
   reverseLoop secondBatch
   restore done@ohMy
 \}
  match :||secondBatch,done@ohMy:params \{
   reverseLoop secondBatch
   restore done@ohMy
 \}
  match :firstBatch||,done@ohMy:params \{
   forwardLoop firstBatch
   restore done@ohMy
 \}
  match :firstBatch,done@ohMy:params \{
   forwardLoop firstBatch
   restore done@ohMy
 \}
}    


Edit: aww, too slow
Post 16 Oct 2012, 21:36
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.