flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > fastcall macro

Author
Thread Post new topic Reply to topic
lovefasm



Joined: 17 Jun 2007
Posts: 22
lovefasm
Code:
format pe console
entry start

include 'Win32AXP.inc'
include 'list.inc'

macro fcall proc,[arg]
{
common
  arg@count = 0

   if ~ arg eq
forward
              arg@count = arg@count + 1
common
 end if

reverse
       if arg@count > 2
         push    arg
 else if arg@count = 2
               if ~ arg in < edx >
                   mov     edx,arg
             end if
      else if arg@count = 1
               if ~ arg in < ecx >
                   mov     ecx,arg
             end if
      end if
      arg@count = arg@count - 1

common
     call    proc
}

macro prteax
{
        cinvoke printf,_fmt,eax
}
_fmt       db      "%d",0ah,0

start:
      fcall Add0
  prteax
      fcall Add1,1
        prteax
      fcall Add2,1,2
      prteax
      fcall Add3,1,2,3
    prteax
      fcall Add4,1,2,3,4
  prteax
      fcall Add5,1,2,3,4,5
        prteax
      ret

Add0:
        xor     eax,eax
     ret

Add1:
        mov     eax,ecx
     ret

Add2:
        mov     eax,ecx
     add     eax,edx
     ret

Add3:
        mov     eax,ecx
     add     eax,edx
     add     eax,dword [esp+4]
   ret     4

Add4:
  mov     eax,ecx
     add     eax,edx
     add     eax,dword [esp+4]
   add     eax,dword [esp+8]
   ret     8

Add5:
  mov     eax,ecx
     add     eax,edx
     add     eax,dword [esp+4]
   add     eax,dword [esp+8]
   add     eax,dword [esp+12]
  ret     12

data import
       library msvcrt,'msvcrt.dll'
       import  msvcrt,\
           printf,'printf'
end data
    
Post 23 Feb 2008, 14:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17714
Location: In your JS exploiting you and your system
revolution
Why only ecx & edx, but not eax?
Post 23 Feb 2008, 14:28
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
if ~ arg in < edx >

why not "if ~ arg eq edx" ?
Post 23 Feb 2008, 15:39
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov
Code:
; its not a very correct but work. incorrect example: fastcall proc , edx, eax, ecx
macro fastcall proc,[arg] {
    common
     local size@ccall
    size@ccall = 3
    if ~ arg eq
    forward
    if size@ccall = 3
   if ~ arg eq eax
     mov     eax,arg
     end if
      size@ccall = 2
    else if size@ccall = 2
        if ~ arg eq edx
     mov     edx,arg
     end if
      size@ccall = 1
    else if size@ccall = 1
        if ~ arg eq ecx
     mov     ecx,arg
     end if
      size@ccall = 0
    else
  pushd   arg
    end if
    common
    end if
    common
    call proc
}    
Post 29 Mar 2008, 16:14
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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.