flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Discussion strategy flexible macro.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 31 Mar 2023, 14:05
Fasmw 1.73.
Idea flexible macro, from combination several macros.
Code:
macro A reg {inc reg}
macro For loop {}
macro Out reg,buf {}
macro flex name,reg,[args] {} ;idea mix macros in one universal for increasing opportunities.
    


In code
Code:
;do mov bl,[edx]  mov [buf2],bl
flex macrNew1,edx,<Out,buf2>

;do inc ebx
flex macrNew2,ebx,A

;do mov ecx,8  mov bl,[eax+ecx]  mov [buf1+ecx],bl and loop 8 times
flex macrNew3,eax,<For,8>,<Out,buf1> 
    
Post 31 Mar 2023, 14:05
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 01 Apr 2023, 09:24
First variant.
Code:
;one uneversal macro flex others simple
;in flex hidden for,while
macro flex a,[p] { local .up
      common
      cnt = 0
      forward
      match x d, p \{
      if x eq for
      display 'for',13,10
      ;a equ a+ecx
      define a a+ecx
      cnt = d
      end if
      \}
      match x, p \{
      if x eq while
      display 'while',13,10
      define a a+ecx
      end if
      \}
       match x d, p \{
      if x eq mout
        if cnt > 0
            xor ecx,ecx
    .up:   mout [a],d+ecx
          end if
        if cnt = 0
           mout [a],d
          end if
        if cnt > 0
           inc ecx
           cmp ecx,cnt
           jb .up
          end if
      end if
      \}
           }
macro mout reg,buf {
      mov bl,reg
      mov [buf],bl
      }  
;in code
ptxt      db 128 dup (0)
ptxt2     db 128 dup (0)

flex    eax,<for 20>,<mout ptxt2> ;asm code as expected. Ok
flex    edx,<mout ptxt> ;ida pro show mov bl,[edx+ecx] ! Why ? I expected mov bl,[edx] 
;another problem define  a+ecx in macro flex broken Out1 name.
flex    Out1,<mout ptxt>
;section bss
Out1 rd 20 ;fasm error Out1+ecx 
    
Post 01 Apr 2023, 09:24
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 01 Apr 2023, 14:10
Variant fixed problems
Code:
macro flex a,[p] { local .up
      common     
      cnt = 0
      define _a2  a
      forward      
      match x d, p \{
      if x eq for
      display 'for',13,10
      define _a2  a+ecx      
      cnt = d
      end if
      \}
      match x, p \{
      if x eq while
      display 'while',13,10
      define _a2  a+ecx      
      end if
      \}
       match x d, p \{      
      if x in <mout,minc>
        if cnt > 0
            xor ecx,ecx
    .up:   x [_a2],d+ecx
          end if
        if cnt = 0
           x [a],d
          end if
        if cnt > 0
           inc ecx
           cmp ecx,cnt
           jb .up
          end if
      end if
      \}   
  }                
    
Post 01 Apr 2023, 14:10
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.