flat assembler
Message board for the users of flat assembler.

 Index > Macroinstructions > Discussion strategy flexible macro.
Author
Roman

Joined: 21 Apr 2012
Posts: 1701
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>

31 Mar 2023, 14:05
Roman

Joined: 21 Apr 2012
Posts: 1701
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

01 Apr 2023, 09:24
Roman

Joined: 21 Apr 2012
Posts: 1701
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
\}
}

01 Apr 2023, 14:10
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum