flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > 64 bit strange macro behavior ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1080
Roman
I write this macro
Code:
macro vCall  cT,[arg] {
              forward
              mov rcx,arg
              mov rdx,arg
              mov r8,arg
              mov r9,arg
              common
              Call cT
                               }
    

If i write in code vCall procA,0,2
I get this:
Code:
mov rcx,0
mov rdx,0
mov r8,0
mov r9,0
mov rcx,2
mov rdx,2
mov r8,2
mov r9,2
Call procA
    

But i want get like do invoke(but invoke big macro).
Code:
mov rcx,0
mov rdx,2
Call procA
    

Or vCall procA,1
Code:
mov rcx,1
Call procA
    

Or vCall procA
Code:
Call procA
    
Post 12 Dec 2020, 09:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
Location: In your JS exploiting you and your system
revolution
At the very least you need something to count which arg you have in the forward loop:
Code:
macro vCall  cT,[arg] {
    common
        arg_index = 0
    forward
        if arg_index = 0
                mov rcx,arg
        else if arg_index = 1
                mov rdx,arg
        else if arg_index = 2
                mov r8,arg
        else if arg_index = 3
                mov r9,arg
        else
                err "too many args"
        end if
        arg_index = arg_index + 1
    common
        Call cT
}    
Post 12 Dec 2020, 09:36
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 641
Location: Russian Federation, Sochi
ProMiNick
Code:
macro vCall  cT,torcx:rcx,tordx:rdx,tor8:r8,tor9:r9,[arg] {
              forward
              ; thour original macro does nothing with 5th and later args, so I left only comment here
              common
              if ~torcx eq rcx
                mov rcx,torcx
              end if
              if ~tordx eq rdx
                mov rdx,tordx
              end if
              if ~tor8 eq r8
                mov r8,tor8
              end if
              if ~tor9 eq r9
                mov r9,tor9
              end if
              Call cT}    

I like to separate stack args from register args because they have different nature.

or even so
Code:
macro invok4  cT,torcx:rcx,tordx:rdx,tor8:r8,tor9:r9 {
              if torcx eq rcx
                mov rcx,torcx
              end if
              if tordx eq rdx
                mov rdx,tordx
              end if
              if tor8 eq r8
                mov r8,tor8
              end if
              if tor9 eq r9
                mov r9,tor9
              end if
              Call [cT]}    

that is then x64 invoke, and less less less (less ...) gready for preprocessor resources(memory & compilation time) in cases of apicalls with 4 and less args.
64bit call is greadyest macro ever written in fasm standart package.
Post 12 Dec 2020, 09:53
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1080
Roman
Thanks !
Post 12 Dec 2020, 10:47
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 954
Location: Belarus
DimonSoft
I can’t find any notion of the colon-syntax (pun not intended) in the documentation, but it works. Have I missed something about the preprocessor and its treatment of the character?
ProMiNick wrote:
Code:
macro vCall  cT,torcx:rcx,tordx:rdx,tor8:r8,tor9:r9,[arg]    
Post 12 Dec 2020, 21:09
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
Location: In your JS exploiting you and your system
revolution
It is a default value if nothing it supplied.
Post 12 Dec 2020, 22:38
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 954
Location: Belarus
DimonSoft
revolution wrote:
It is a default value if nothing it supplied.

I assumed it could be that but FASM.pdf says it’s = character that is used for default values. I feel I’ve seen a discussion of the feature at the forum some time ago but can’t recall any details.
Post 13 Dec 2020, 12:42
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
Location: In your JS exploiting you and your system
revolution
Both work fine:
Code:
macro x val=0 { display val+'0' }
macro y val:0 { display val+'0' }
x
x 1
y
y 1

;output:
;0101
;1 passes, 0 bytes.    
Post 13 Dec 2020, 12:47
View user's profile Send private message Visit poster's website 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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.