I've written the following bunch of macros just to deal with procedures
%macro proc 0-*
%push procedure
%stacksize flat
%assign %$argsize %0 ; auxiliary preprocessor variable
%rep %0
%arg %1
%rotate 1
%endrep
%if %0
push ebp
mov ebp, esp
%endif
%endmacro
%macro endp 0
%ifctx procedure
%pop
%else
%error "No procedure to end."
%endif
%endmacro
%macro ret 0
%if %$argsize
mov esp, ebp
pop ebp
ret %$argsize * __BITS__ / 8 ; some trickery here (maybe wrong)
%assign %$argsize 0
%else
ret
%endif
%endmacro
%macro ret 1
ret %1
%endmacro
%macro local 0-*
%ifctx procedure
%assign %$localsize 0
%rep %0
%local %1
%rotate 1
%endrep
sub esp, %$localsize
%else
%error "local not in a procedure."
%endif
%endmacro
%idefine proc proc
%idefine endp endp
%idefine local local
With these macro I'm able to define procedures in a MASM-fashon, i.e.
===================================
my_proc PROC arg1:DWORD, arg2:DWORD, ...
LOCAL local1:DWORD, local2:DWORD, ..
ret
ENDP
===================================
The problem is that even if the previous "procedure" stack have been popped out
from stack, it seems that I'm unable to define a new procedure with some of the same
argument names. Declaring
===================================
foo PROC arg1:DWORD
ret
ENDP
===================================
after my_proc gives me the error "`%arg' missing argument parameter" for each argument
that shares a previously used name (in this case it would occur just once).
Do NASM have any features capable of solving this problem?