News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Macro ?

Started by minor28, August 19, 2012, 06:03:05 AM

Previous topic - Next topic

minor28

I find it hard to write macros.

For example this macro

TESTING MACRO args:VARARG
LOCAL buffer

buffer equ <>
forc char,<args>
buffer CATSTR buffer,<char>
endm
exitm <buffer>
ENDM

%echo TESTING("!") ; = ""
%echo TESTING("\") ; = ""
%echo TESTING("\\") ; = "\"
%echo TESTING("<>") ; = ""



The "\" could be written with an escape char "\\" but how do i write the macro to accept the other characters?

FORTRANS

Hi,

   You can try the escape character.  But it isi probably
easier to use hexadecimal/numeric representations
of those characters.

Regards,

Steve N.

jj2007

Try this...
include \masm32\include\masm32rt.inc
TESTING MACRO args:VARARG
LOCAL buffer, tmpL$, tmpR$, is
buffer equ <args>
is INSTR <args>, <!!>
if is
tmpL$ SUBSTR <args>, 1, is-1
tmpR$ SUBSTR <args>, is+1
buffer CATSTR tmpL$, <!!>, tmpR$
endif
is INSTR <args>, <!<>
if is
tmpL$ SUBSTR <args>, 1, is-1
tmpR$ SUBSTR <args>, is+1
buffer CATSTR tmpL$, <!<>, tmpR$
endif
is INSTR <args>, <!>>
if is
tmpL$ SUBSTR <args>, 1, is-1
tmpR$ SUBSTR <args>, is+1
buffer CATSTR tmpL$, <!>>, tmpR$
endif
exitm <buffer>
ENDM
.code
start:
% echo TESTING("!!") ; = ""
% echo TESTING("\ (impossible)") ; = ""
% echo TESTING("\\") ; = "\"
% echo TESTING("<>") ; = ""
.err
exit
end start