flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [SOLVED]FASM:What is wrong with this macroset?

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 07 Nov 2019, 15:04
Code:
macro form@callstack [arg] {
 reverse
        if ~ arg eq stack
                pushd arg
        else
                if (~ stack@call) | (stack@call=size@call)
                        stack@call = size@call+4
                else
                        display 'real and stack args are mixed'
                        error
                end if
        end if
        size@call = size@call+4
        match =double any,arg \\{ size@call = size@call+4 } ; [EDITED] - error was here

macro fastcall@initreg [regname,arg] {
 local check
        check = $
        match first rest, arg \{
                match =addr , first \\{ lea regname,[rest] \\}
                if ~ (check-$) & first eqtype dword
                        mov regname,dword rest
                end if \}
        if (~(check-$)) & (~ arg eq regname)
                mov regname,dword arg
        end if }

macro prepare dummy,args& {
        size@call = 0
        stack@call = 0
        if ~ args eq
                form@callstack args
        end if }

macro unstack dummy*,args*& {
 local counter
        counter = 0
        irp i,args \{ counter = counter + 1 \}
        add esp, counter*4 }

macro %call proc,toeax:eax,toedx:edx,toecx:ecx,C:0,args& {
        prepare proc,args
        fastcall@initreg eax,toeax,\
                         edx,toedx,\
                         ecx,toecx
        call proc
        if C & size@call
                add esp,size@call
        end if }

macro stdcall proc,args& { %call proc,,,,,args }     ; directly call STDCALL procedure

macro invoke proc,args& { %call dword [proc],,,,,args }    ; indirectly call STDCALL procedure

macro ccall proc,args& { %call proc,,,,1,args }    ; directly call CDECL procedure

macro cinvoke proc,args& { %call dword [proc],,,,1,args }    ; directly call CDECL procedure

macro fastcall proc,toeax,toedx,toecx,args& { %call proc,toeax,toedx,toecx,,args }

USE32


unstack 0,0
stdcall 2,1
ccall 1,2,3
invoke 4,5,6
fastcall 7,8,9,1,2     


What for? in standart set for x86 absent fastcall32.
They are more nesting friendly - 1 common part.
While not added "fastcall" and "toeax:eax,toedx:edx,toecx:ecx" to "%call" all was compiled OK.

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.


Last edited by ProMiNick on 08 Nov 2019, 11:04; edited 1 time in total
Post 07 Nov 2019, 15:04
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20424
Location: In your JS exploiting you and your system
revolution 08 Nov 2019, 08:35
It would help if you gave some context.

What is the problem you experience? What does it do wrong? What do you want it to do?
Post 08 Nov 2019, 08:35
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 08 Nov 2019, 09:41
Thanks for viewing and replying revolution.

I found error myself:
instead of
Code:
match =double any,arg \\{ size@call = size@call+4 }    

I should use
Code:
match =double any,arg \{ size@call = size@call+4 \} }    


Last edited by ProMiNick on 08 Nov 2019, 09:57; edited 1 time in total
Post 08 Nov 2019, 09:41
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20424
Location: In your JS exploiting you and your system
revolution 08 Nov 2019, 09:51
So which part isn't working for you?
Post 08 Nov 2019, 09:51
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.