The MASM Forum

General => The Campus => Topic started by: minor28 on August 19, 2012, 06:03:05 AM

Title: Macro ?
Post by: minor28 on August 19, 2012, 06:03:05 AM
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?
Title: Re: Macro ?
Post by: FORTRANS on August 19, 2012, 07:16:50 AM
Hi,

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

Regards,

Steve N.
Title: Re: Macro ?
Post by: jj2007 on August 19, 2012, 08:12:12 AM
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