flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > macros for find the operand type

Author
Thread Post new topic Reply to topic
maxas70912



Joined: 30 Nov 2019
Posts: 2
maxas70912
.
For example I will give the code in pseudo language
Code:
macros mov arg1, arg2 {
if (arg2 = dword [memory])
...
}
    


How to implement this example in the FASM macro language ??????


.
Post 30 Nov 2019, 17:09
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 460
Location: Russian Federation, Sochi
ProMiNick
for that reason exist eqtype

look at example I workaround of ability of push(pop) to get reg sequence or usual operand:
Code:
; Macroinstructions for defining and calling procedures

include 'proc32.inc'

espFixer=0
macro parameters [arg] {
 common local argsize,localbytes,espPos,..retaddr
        virtual at 0
                ..retaddr dd ?
                        define retaddr ..retaddr+esp+espFixer
                        define localbase ..retaddr+esp+espFixer-localbytes
                if ~arg eq
 forward
                        local ..arg
                        ..arg dd ?
                        define arg ..arg+esp+espFixer
 common
                end if
                argsize = $-4
        end virtual
        espPos = 0
        macro locals \{
                \local espPosInner
                espPosInner = espPos
                virtual at espPosInner
                        macro label def \\{ match . type,def> \\\{ esplocal@proc .,label,<type \\\} \\}
                        struc db [val] \\{ \\common esplocal@proc .,db,val \\}
                        struc du [val] \\{ \\common esplocal@proc .,du,val \\}
                        struc dw [val] \\{ \\common esplocal@proc .,dw,val \\}
                        struc dp [val] \\{ \\common esplocal@proc .,dp,val \\}
                        struc dd [val] \\{ \\common esplocal@proc .,dd,val \\}
                        struc dt [val] \\{ \\common esplocal@proc .,dt,val \\}
                        struc dq [val] \\{ \\common esplocal@proc .,dq,val \\}
                        struc rb cnt \\{ esplocal@proc .,rb cnt, \\}
                        struc rw cnt \\{ esplocal@proc .,rw cnt, \\}
                        struc rp cnt \\{ esplocal@proc .,rp cnt, \\}
                        struc rd cnt \\{ esplocal@proc .,rd cnt, \\}
                        struc rt cnt \\{ esplocal@proc .,rt cnt, \\}
                        struc rq cnt \\{ esplocal@proc .,rq cnt, \\} \}

        macro endl \{
                        purge label
                        restruc db,du,dw,dp,dd,dt,dq
                        restruc rb,rw,rp,rd,rt,rq
                        espPos = espPos+(($-$$+3) and (not 3))
                        end virtual \}

        macro endp \{
                localbytes = espPos
                match any,arg \\{
 forward
                        restore arg
common
                \\}
                restore retaddr,localbase
                purge endp,push,pushd,pop,sub,add,invoke,cominvk,comcall,stdcall,ret,locals,endl
                match all,all@vars \\{ restore all \\}
                restore all@vars
                espFixer=0 \}

        macro pushd [arg1] \{
        \common  \local ..tmp
        \forward
                ..tmp = espFixer
                pushd    arg1
                espFixer =..tmp+4
        \}

        macro push [arg1] \{
        \common  \local ..tmp
        \forward
                if (arg1 eqtype [0]) | (arg1 eqtype byte[0]) | (arg1 eqtype eax) | (arg1 eqtype 0)
                        ..tmp = espFixer
                        push     arg1
                        espFixer =..tmp+4
                else
                        irps ..arg1, arg1 \\{
                                ..tmp = espFixer
                                push     ..arg1
                                espFixer =..tmp+4 \\}
                end if
        \}

        macro pop [arg1] \{
        \common  \local ..tmp
        \forward
                if (arg1 eqtype [0]) | (arg1 eqtype byte[0]) | (arg1 eqtype eax) | (arg1 eqtype 0)
                        ..tmp = espFixer
                        pop      arg1
                        espFixer =..tmp-4
                else
                        irps ..arg1, arg1 \\{
                                ..tmp = espFixer
                                pop     ..arg1
                                espFixer =..tmp-4 \\}
                end if
        \}

        macro sub arg1,arg2 \{
                sub arg1,arg2
                match   =esp,arg1 \\{ espFixer =espFixer+arg2 \\} \}

        macro add arg1,arg2 \{
                add arg1,arg2
                match   =esp,arg1 \\{ espFixer =espFixer-arg2 \\} \}

        macro invoke proc,[arg1] \{
        \common \local ..tmp
                ..tmp = espFixer
                invoke proc,arg1
                espFixer =..tmp \}

        macro invoks proc,[arg1] \{
        \common
                if ~ arg1 eq
        \reverse
                        if ~ arg1 eq stack
                                pushd arg1
                        end if
        \common
                end if
                call dword [proc]
        \forward
                if ~ arg1 eq
                        espFixer =espFixer-4
                end if \}

        macro cominvk object,proc,[arg1] \{
        \common \local ..tmp
                ..tmp = espFixer
                cominvk object,proc,arg1
                espFixer =..tmp \}

        macro comcall handle,interface,proc,[arg1] \{
        \common \local ..tmp
                ..tmp = espFixer
                comcall handle,interface,proc,arg1
                espFixer =..tmp \}

        macro stdcall proc,[arg1] \{
        \common \local ..tmp
                ..tmp = espFixer
                stdcall proc,arg1
                espFixer =..tmp \}

        macro ret arg1:argsize \{
                if localbytes
                        add esp, localbytes
                end if
                ret arg1 \}

        if localbytes
                sub esp, localbytes
        end if }

macro esplocal@proc name,def,[val] {
 common
        name def val }

macro esplocal@proc name,def,[val] {
 common
        match vars, all@vars \{ all@vars equ all@vars, \}
        all@vars equ all@vars name
        local ..var
        ..var def val
        define name ..var}

macro procedure definition& {
        match (args),definition \{ parameters args \}
        match (),definition \{ parameters \} }

macro prepare dummy,[arg]
 { common
        if ~ arg eq
   reverse
                pushd arg
   common
        end if }

macro unstack dummy,[arg]
 { common local counter
        if ~ arg eq
                counter = 0
   forward
                counter = counter + 1
   common
                add     esp, counter*4
        end if }    

there is more
eqtype ''
eqtype 1f
eqtype dword 1f

but there is no expression solving before eqtype compare:
ebx-ebx+4 eqtype 0 will return false.
eax+eax eqtype eax*2 will return false too
Post 30 Nov 2019, 17:30
View user's profile Send private message Send e-mail Reply with quote
maxas70912



Joined: 30 Nov 2019
Posts: 2
maxas70912
Thank you very much, your answer helped a lot
Quote:

there is more
eqtype ''
eqtype 1f
eqtype dword 1f

but there is no expression solving before eqtype compare:
ebx-ebx+4 eqtype 0 will return false.
eax+eax eqtype eax*2 will return false too
Post 30 Nov 2019, 20:00
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-2020, Tomasz Grysztar.

Powered by rwasa.