I was just running through a MACRO and found to be confused with it! Here,

reparg MACRO arg
 LOCAL nustr
   quot SUBSTR <arg>,1,1
 IFIDN quot,<">            ;; if 1st char = "
   .data
     nustr db arg,0        ;; write arg to .DATA section
   .code
   EXITM <ADDR nustr>      ;; append name to ADDR operator
 ELSE
   EXITM <arg>             ;; else return arg
 ENDIF
ENDM


When I use this MACRO as

mov eax, reparg("Test")


It errors out. I changed the ADDR keyword in the macro to OFFSET, then it assembled and compiled well. Can I assume that the nustr declared within the MACRO is a global variable and we should be using OFFSET keyword to return the address of the variable? Is my understanding right.

Coz I read somewhere the OFFSET keyword should be used for accessing global variables and ADDR to be used to access the local variables used with a particular function? Pls correct me..

Thanks in advance
Posted on 2009-09-23 07:42:57 by karthikeyanck
ADDR is part of the INVOKE macro in MASM, it's not a regular directive like OFFSET.
The difference between ADDR and OFFSET is that OFFSET is literally just that: the offset of a variable from the start of the section that it's in. ADDR can be either an offset, or a different type of address, such as a base pointer + offset, like you'd have with local variables (on stack). Think of ADDR as 'anything that you could put in a lea instruction'. Offset is always just a constant value, and can only be used with predefined data (labels) in a section.
Posted on 2009-09-23 08:07:34 by Scali
Then can I assume there is no real use of ADDR keyword? I understand that I can still use OFFSET in INVOKE's.. Can you please give me a real world example where ADDR is to be used mandatorily?

Thanks for your reply
Posted on 2009-09-23 08:12:10 by karthikeyanck
For example when you have some kind of local variable in your proc, and you want to pass it with INVOKE.
Then ADDR variable will work, but OFFSET variable will not, because the variable doesn't have an offset, its address is of the form .
What you would normally do then is this, if you want the address in a register:
lea eax,
Posted on 2009-09-23 09:13:21 by Scali