flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > Basic macro for procs and macros.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 01 Oct 2024, 11:40
For fast writing code. I create macro basic fasmw 1.73.
My variant simple basic:
Code:
macro _nxt r,lb, rest=0{ dec r
                  jnz lb 
If rest >0
restore lb
end if
}
macro _nxtp r,lb, rest=0{pop r 
                  dec r
                  jnz lb 
If rest >0
restore lb
end if 
}
macro mBasic [args] { common
macro mGetArg af*,base*,[arg] \{ \common
        ;match any,GetBufr \\{ define GetBufr any+af
        mov base,[GetBufr+af]
        GetReg equ base
        ;\\}
        \forward match =+ x, arg \\{ add base, x \\}
                 match =- x, arg \\{ sub base, x \\}
                 ;match =:=~ x, arg \\{ shl base, x \\}
                 match "(", arg \\{ push base \\}
                 match ")", arg \\{ pop base \\}
                 match "{(", arg \\{ local .lb
                                         .lb: push base
                                         get_lb equ .lb
                                         display "{"
                 \\}
                 match ")}", arg \\{    pop base
                                        dec base
                                        ;test base, base
                                        jnz get_lb
                                        restore get_lb
                                         display "}"
                 \\}
                 match "{", arg \\{ local .lb
                                         .lb:
                                         get_lb equ .lb
                                         display "{"
                 \\}
                 match "}", arg \\{ test base, base
                                        jnz get_lb
                                        restore get_lb
                                         display "}"
                 \\}
                 match "vec4" x, arg \\{ irpEqsVec4 equ x
                                         x\\#\\_type equ 'vec4'
                                         ;display x_type
                 \\}
                 match "ivec" x, arg \\{ irpEqsIVec equ x
                                         x\\#\\_type equ 'int'
                                         ;display x_type
                 \\}
                 match ">" x, arg \\{ display '>'
                       shr base, x \\}
                 match "<" x, arg \\{ shl base, x \\}
                 match ":" x, arg \\{ x: x\\#\\_type equ 'label' \\}
                 match "!0": x, arg \\{ test base, base
                                        jz x   \\}
                 match "!0", arg \\{ test base, base
                                        jz @f   \\}
                 match "!>0": x, arg \\{ test base, base
                 jnz x   \\}

                 match "to", arg \\{ ;display 'to;'
                 mov [GetBufr+af],base   \\}
                 match "to": x, arg \\{ ;display 'to2;'
                 mov x,base   \\}
                 match #:x , arg \\{ x equ base  \\}
                 match : , arg \\{ mov base, [base] \\}
                 match '(do)' , arg \\{ push base
                                        call base
                                        pop  base
                                        \\}
                 match '(do)': x, arg \\{ push base
                                          call dword x
                                          pop  base
                                          \\}
                 match 'do' , arg \\{ call base \\}
                 match 'do': x, arg \\{ call dword x \\}
                 match 'ptR'x:z, arg \\{ mov x,[z]
                                          add z,GetptrR
                       \\}
                 match 'ptW'x:z, arg \\{ mov [z],x
                                          add z,GetptrW
                       \\}
                 match 'ptR_'x:z, arg \\{ mov x,[z]  \\}
                 match 'ptW_'x:z, arg \\{ mov [z],x  \\}
                 match =* x , arg \\{ x base \\}
    \}
    if ~ args eq
    forward mGetArg args
    common  end if
    purge   mGetArg
@@:
}
macro mBasic_ [args] { common
macro mGetArg base*,[arg] \{ \common
        ;match any,GetBufr \\{ define GetBufr any+af
        ;mov base,[GetBufr+af]
        GetReg equ base
        ;\\}
        \forward match =+ x, arg \\{ add base, x \\}
                 match =- x, arg \\{ sub base, x \\}
                 ;match =:=~ x, arg \\{ shl base, x \\}
                 match "(", arg \\{ push base \\}
                 match ")", arg \\{ pop base \\}
                 match "{(", arg \\{ local .lb
                                         .lb: push base
                                         get_lb equ .lb
                                         display "{"
                 \\}
                 match ")}", arg \\{    pop base
                                        dec base
                                        ;test base, base
                                        jnz get_lb
                                        restore get_lb
                                         display "}"
                 \\}
                 match "{", arg \\{ local .lb
                                         .lb:
                                         get_lb equ .lb
                                         display "{"
                 \\}
                 match "}", arg \\{ test base, base
                                        jnz get_lb
                                        restore get_lb
                                         display "}"
                 \\}
                 match "vec4" x, arg \\{ irpEqsVec4 equ x
                                         x\\#\\_type equ 'vec4'
                                         ;display x_type
                 \\}
                 match "ivec" x, arg \\{ irpEqsIVec equ x
                                         x\\#\\_type equ 'int'
                                         ;display x_type
                 \\}
                 match ">" x, arg \\{ display '>'
                       shr base, x \\}
                 match "<" x, arg \\{ shl base, x \\}
                 match ":" x, arg \\{ x: x\\#\\_type equ 'label' \\}
                 match "!0": x, arg \\{ test base, base
                                        jz x   \\}
                 match "!0", arg \\{ test base, base
                                        jz @f   \\}
                 match "!>0": x, arg \\{ test base, base
                 jnz x   \\}

                 match "to", arg \\{ ;display 'to;'
                 mov [GetBufr],base   \\}
                 match "to": x, arg \\{ ;display 'to2;'
                 mov x,base   \\}
                 match #:x , arg \\{ x equ base  \\}
                 match : , arg \\{ mov base, [base] \\}
                 match '(do)' , arg \\{ push base
                                        call base
                                        pop  base
                                        \\}
                 match '(do)': x, arg \\{ push base
                                          call dword x
                                          pop  base
                                          \\}
                 match 'do' , arg \\{ call base \\}
                 match 'do': x, arg \\{ call dword x \\}
                 match 'ptR'x:z, arg \\{ mov x,[z]
                                          add z,GetptrR
                       \\}
                 match 'ptW'x:z, arg \\{ mov [z],x
                                          add z,GetptrW
                       \\}
                 match 'ptR_'x:z, arg \\{ mov x,[z]  \\}
                 match 'ptW_'x:z, arg \\{ mov [z],x  \\}
                 match =* x , arg \\{ x base \\}
    \}
    if ~ args eq
    forward mGetArg args
    common  end if
    purge   mGetArg
@@:
}
    


Last edited by Roman on 06 Oct 2024, 04:05; edited 2 times in total
Post 01 Oct 2024, 11:40
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 01 Oct 2024, 11:43
In code:
Code:
GetptrR equ 4  ;offset for read data
GetptrW equ 4 ;offset for write data
macro GetAlz a,b { mBasic <0,ecx,"!0","ptR"a:esi,"ptW"b:edi,"ptR_"edx:esi,"ptW_"edx:edi> }

GetAlz  ebp,dword 11
;or this variant
mBasic <0,ecx,"!0","ptR"edx:esi,"ptW"edx:edi,"ptR_"edx:esi,"ptW_"edx:edi>
    
Post 01 Oct 2024, 11:43
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 01 Oct 2024, 11:45
Example loop.
Code:
MyProc1: inc edx
              ret
;data
pp dd 4,4,8

;in code
mov esi,pp
GetBufr equ esi
mBasic <0,ecx,"!0","{(","(do)",-1,")}">

;or without push. '(' mean push.  ')' mean pop.
;do loop while ebx > 0. '!0' mean if ebx = 0 exit from mBasic
mBasic <8,ebx,"!0","{","do":MyProc1,-1,"}">
    
Post 01 Oct 2024, 11:45
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 04 Oct 2024, 11:40
Code:
mov ebx,11
mBasic_ <ebx,"!0":.l1,"{","do":MyProc1,-1,#:regLoop1>
      some code
      _nxt regLoop1,get_lb  ;get_lb = "{"
.l1:
    
Post 04 Oct 2024, 11:40
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.