flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > new proc macro that lets u use ebp

Author
Thread Post new topic Reply to topic
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
Code:
macro push arg {
       push arg
    if defined PUSH_COUNTER
             PUSH_COUNTER=PUSH_COUNTER+1
 end if
}

macro pop arg {
        pop arg
     if defined PUSH_COUNTER
             PUSH_COUNTER=PUSH_COUNTER-1
 end if
}

macro proc name, [arg] {
common
     if used name | defined INCLUDE_ALL_PROCS
    PROC_NAME equ name
  PARAM_COUNTER equ 0
 LOCAL_COUNTER equ 0
 PUSH_COUNTER=0
 
 if ~ arg eq
forward
      PARAM_COUNTER equ PARAM_COUNTER+1
   arg equ esp+(PARAM_COUNTER+LOCAL_NUM+PUSH_COUNTER)*4
common
      name#% = PARAM_COUNTER
      else
        name#% = 0
  end if
name:
}

macro begin {
     LOCAL_NUM=LOCAL_COUNTER
     if LOCAL_NUM>0
           sub esp, (LOCAL_NUM*4)
      end if
}

macro return {
 if PUSH_COUNTER<>0
            display 'WARNING: push/pop miscount',13,10
    end if

  if LOCAL_NUM>0
           add esp, (LOCAL_NUM)*4
      end if
      PARAM_NUM=PARAM_COUNTER
     ret (PARAM_NUM*4)
}

macro endp {
        if PUSH_COUNTER<>0
            display 'WARNING: push/pop miscount',13,10
    end if
      end if
}

macro ldd name {
       name equ esp+(LOCAL_COUNTER+PUSH_COUNTER)*4
 LOCAL_COUNTER equ LOCAL_COUNTER+1
}

macro lrd name, dwords {
    name equ esp+(LOCAL_COUNTER+PUSH_COUNTER)*4
 LOCAL_COUNTER equ LOCAL_COUNTER+dwords
}

macro stdcall proc, [arg] {
common
  PARAM_COUNTER = 0
   
    if ~ arg eq
reverse
      push arg
    PARAM_COUNTER = PARAM_COUNTER+1
common
   end if
      
    if proc#% <> PARAM_COUNTER
            display 'WARNING: Param miscount',13,10
       end if

  call proc
}

    


Usage:

Code:
stdcall name, 10, 100

proc name, par1, par2
ldd .Local1 ; local dword
begin
   code
   return ; U can also have multiple return points
endp
    


Features:
U can freely use ebp and still have named locals, even pushs/pops won't break your code
Warns if param miscount
Warns if push/pop miscount
Include procs only if used or INCLUDE_ALL_PROCS is defined

Think that was it.. Comments appreciated.
Post 26 Sep 2003, 10:16
View user's profile Send private message Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S.
Please check my note about "pop" macro in this thread:
Post 22 Feb 2004, 12:01
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-2019, Tomasz Grysztar.

Powered by rwasa.