News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

text macro

Started by korte, March 18, 2007, 10:16:00 PM

Previous topic - Next topic

korte


How to define macro?


aaaXXXbbb proc
.
.
.
aaaXXXbbb endp


   defi "XXX"

I want to macro define dword pointer to aaaXXXbbb, but macro parameter only "XXX" string.
(aaa bbb fix)

thx


MichaelW

I can't think of any universal way to do this. This will work within limits, but if the macro is called from within a procedure that has a stack frame, MASM will return "error A2144: cannot nest procedures".

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    defpp MACRO tag:REQ
      LOCAL pname
      LOCAL qtag                      ;; this just for test
      pname CATSTR <aaa>,<tag>,<bbb>
      qtag  CATSTR <">,<tag>,<">      ;; this just for test
      jmp @F
      pname proc
        print %qtag,13,10             ;; this just for test
        ret
      pname endp
    @@:
      EXITM <OFFSET pname>
    ENDM

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

testproc proc ;xxxxx:DWORD
    mov eax, defpp(ZZZ)
    call eax
    call aaaZZZbbb
    ret
testproc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    mov eax, defpp(XXX)
    call eax
    call aaaXXXbbb
    mov eax, defpp(YYY)
    call eax
    call aaaYYYbbb

    call testproc

    inkey "Press any key to exit..."
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
eschew obfuscation

zooba

What MichaelW has posted should work fine.

To get around the problem of calling it within a procedure, you can use a different (named) segment:

defpp MACRO tag:REQ
      LOCAL pname
      LOCAL qtag                      ;; this just for test

.code AUTO_FUNCTIONS                  ;; new line here
      pname CATSTR <aaa>,<tag>,<bbb>
      qtag  CATSTR <">,<tag>,<">      ;; this just for test
;;      jmp @F                        ;; don't need this line anymore
      pname proc
        print %qtag,13,10             ;; this just for test
        ret
      pname endp
;;    @@:                             ;; don't need this line anymore
.code                                 ;; new line here
      EXITM <OFFSET pname>
ENDM


You don't need to refer to the segment by name at all, it will (should) just work (I haven't tested this particular case, but I have used this technique before). The code will be placed in a second segment within your executable, which may increase the overall size, depending on whether the linker merges the sections or not.

Cheers,

Zooba :U

korte

sorry litle english. (reading ok, but not write question)

My problem.
Procedure already define, i want only dword pointer.
like:
   dd  offset aaaXXXbbb

I want to define only "XXX" string.
XXX ~ object name aaa...bbb method

I writing
   definemacro "XXX"
   definemacro "YYY"

want to output
  dd offset aaaXXXbbb
  dd offset aaaYYYbbb



thanks



zooba

In that case:

definemacro MACRO tag
    dd offset aaa&tag&bbb
ENDM


Cheers,

Zooba :U

korte

thx zooba very simple and nice

and also thanks MichaelW