Can some of you "MACRO gurus" explain why is this and how you can live with it? :dazzled:
I mean what to do that MASM do not missinterpret the symboles in a larger file with macros? ::)
.686p
.model flat, stdcall
option casemap :none
NEWDATA TEXTEQU <>
Pilot MACRO
NEWDATI TEXTEQU <NEWDATAS> ;-> NEWDATAS
%echo NEWDATI
Temp SUBSTR NEWDATI,1,6 ;-> NEWDAT
%echo Temp
%echo @SubStr(NEWDATI,1,6) ;-> NEWDAT
Temp SUBSTR NEWDATI,1,7 ;-> <> - "NEWDATI,1,7" get "NEWDATA" and expand to <> before get assigned to Temp -I just guessing- ???
%echo Temp
%echo @SubStr(NEWDATI,1,7) ;-> NEWDATAS - Should return "NEWDATA" if expanded should be <> but why "NEWDATAS" ???
ENDM
.data
.code
start:
Pilot
end start
EDIT:
I like to get "NEWDATA" back somehow is it possible?
Quote from: Ficko on June 16, 2010, 05:18:16 PM"NEWDATI,1,7" get "NEWDATA" and expand to <> before get assigned to Temp -I just guessing- ???
your assumption is right.
to your last macro line:
%echo @SubStr(NEWDATI,1,7)
When calling function like macros, you must use the expansion operator % to get text macros contents.
In your case @SubStr() returns the string "NEWDATI", which is then expanded to 'NEWDATAS'
However, when @SubStr(%NEWDATI,1,7) returns 'NEWDATA', it will be expand too <> -> rename the textmaco NEWDATA to get it work.
You will always be on the save side by using
<%textmacro> for passing text macros and
%my_num for constans.
The angel brackets are not allways needed, but IMO the make more clear what should be done. The only exception are masm predefined macros, which doesn't like the expansion operator for passing numeric values:
my_const = 1
xyz SUBSTR <abcdefg>,%my_const,1 ; generates error - remove the %
The same applies for INSTR. The function like forms of these macros are not affected (@InStr()/@SubStr())
It is also useful (for macro debugging :bg) to generate a listing file:
/FlList.txt /Snuse .listall and .nolist in your source code to controll the listings output.
Thanks "qWord"!
So basically if I have a huge collection of macros in a file I should collect all the defines - EQUs, TEXTEQUs - outside the macros and place them in one place like the beginning of the file.
- Just to see what is in use because they can allways conflict with other usages inside the macros.-
There is no way to tell MASM not to expand something or to tell him only expand something ones right ?
I have one more question.
What about the keyword "LOCAL".
I see that sometimes it used sometimes not.
Are not all variables locals anyway inside macros if not defined outside? ::)
Quote from: Ficko on June 17, 2010, 07:24:05 AM
Are not all variables locals anyway inside macros if not defined outside? ::)
No, they aren't. Occasionally, you need global assembly-time constants and variables, e.g. for constructing a For ... Next macro, i.e. two different macros that rely on each other.
Another thing to keep in mind is that ml.exe and jwasm.exe are not 100% compatible. Try assembling the snippet below with ML/JWasm.
Quoteinclude \masm32\include\masm32rt.inc
Dim MACRO NewMac:REQ
LOCAL isL, MacName$, nustr
isL INSTR <NewMac>, <(>
MacName$ SUBSTR <NewMac>, 1, isL-1
.data
% @CatStr(<nustr db "&MacName$&", 0>)
.code
MsgBox 0, offset nustr, "JWasm with %: My$", MB_OK
ENDM
.code
start: Dim My$(99)
exit
end start
RichMasm (http://www.masm32.com/board/index.php?topic=12460) options
OPT_Assembler JWasm
Quote from: Ficko on June 17, 2010, 07:24:05 AM
Just to see what is in use because they can allways conflict with other usages inside the macros.
Using LOCALs avoid this conflict. At macro evaluation, the LOCALs names get replaced by something like ??000A - this make them unique.
However, locals are an finite resource: you can only create 2^16 of them :bg
Generally locals are not needed. You can make text macros and constants unique by adding an prefix or suffix: e.g.: ??myconst=0.
When doing so, do not forget do clear/zero them at macro begin.
count_char macro lit:req
LOCAL cntr
cntr = 0 ; unique through LOCAL
FORC chr,<&lit>
cntr = cntr + 1
ENDM
EXITM %cntr
endm
count_char macro lit:req
?ccm_cntr = 0 ; unique constant name
FORC chr,<&lit>
?ccm_cntr = ?ccm_cntr + 1
ENDM
EXITM %?ccm_cntr
endm
Quote from: Ficko on June 17, 2010, 07:24:05 AMThere is no way to tell MASM not to expand something or to tell him only expand something ones right ?
no