Hi all,
I've been experimenting with masm's macro capabilities and I've come up with this macro which does the same as C's enum

have a go and let me know how it works for you...



;version1 for use in .data segment
enum macro _param_:VARARG
IFNB <_param_>
_count_=0
_temp_ textequ <0>
for _arg_,<_param_>
_pos_ instr <_arg_>,<=>
if _pos_ ne 0
_temp_ SubStr <_arg_>,_pos_+1
@SubStr(<_arg_>,1,_pos_-1) dd _temp_
_count_=1
else
_arg_ dd _temp_+_count_
_count_=_count_+1
endif
endm
ENDIF
endm




;version2 for use anywhere
enum macro _param_:VARARG
IFNB <_param_>
_count_=0
_temp_ textequ <0>
for _arg_,<_param_>
_pos_ instr <_arg_>,<=>
if _pos_ ne 0
_temp_ SubStr <_arg_>,_pos_+1
@SubStr(<_arg_>,1,_pos_-1) equ _temp_
_count_=1
else
_arg_ equ _temp_+_count_
_count_=_count_+1
endif
endm
ENDIF
endm


As you can see they are virtually identical I couldn't find a way to check if the macro was invoked from the .data section...

an example of how to use it


enum AA,BB=9,CC,XX,YY,ZZ=5,WW,VV=0,UU,TT,RR=1000AH,QQ
Posted on 2002-06-26 19:22:01 by MArtial_Code
Cool macro! @CurSeg contains the name of the current segment (note: case sensitive).
Posted on 2002-06-26 19:43:31 by bitRAKE
Thanks for the tip Bitrake...
Here's an updated version of the enum macro it will work from anywhere. if invoked from the .data section then it creates the specified variables as dwords. If invoked from anywhere else it defines the specified constants



enum macro _param_:VARARG
_segname_ textequ @CurSeg
_val_=0
% forc _chr_,_segname_
_val_=_val_+'&_chr_'
endm
IFNB <_param_>
_count_=0
_temp_ textequ <0>
_ldata_ textequ <_DATA>
for _arg_,<_param_>
_pos_ instr <_arg_>,<=>
if _pos_ ne 0
_temp_ SubStr <_arg_>,_pos_+1
if _val_ ne 179H ;;179H ='_' + 'D' + 'A' + 'T' + 'A'
@SubStr(<_arg_>,1,_pos_-1) equ _temp_
else
@SubStr(<_arg_>,1,_pos_-1) dd _temp_
endif
_count_=1
else
if _val_ ne 179H ;;179H ='_' + 'D' + 'A' + 'T' + 'A'
_arg_ equ _temp_+_count_
else
_arg_ dd _temp_+_count_
endif
_count_=_count_+1
endif
endm
ENDIF
endm


example of use:



enum AA,BB=9,CC,XX,YY,ZZ=5,WW,VV=0,UU,TT,RR=1000AH,QQ
Posted on 2002-06-27 06:06:14 by MArtial_Code