Author Topic: %arg and %local in contexts  (Read 6810 times)

Gabriele

  • Guest
%arg and %local in contexts
« on: October 01, 2008, 12:36:59 PM »
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?

Offline H. Peter Anvin

  • NASM Developer
  • Jr. Member
  • *****
  • Posts: 18
Re: %arg and %local in contexts
« Reply #1 on: October 02, 2008, 01:41:33 AM »
Unfortunately, NASM currently doesn't let you define context-local macros without leading %$.  That is doubtlessly a bit of a defect, and it would be nice to fix that.

 

SMF spam blocked by CleanTalk