Ok, I am missing something here. How do I reference the LOCATION of a LOCAL variable. I tried ADDR (works for "INVOKE" but not for "mov esi, ADDR LocVar"). I tried to use both ADDR and OFFSET, but both failed. OBTW, this is with MASM 9.0. I finally declared the data variables in .DATA? and used OFFSET, but, isn't there a way to reference the LOCATION of LOCAL variables?
The MASM32 help files do not have any help for this.
Dave.
LEA calculates the address at runtime :t
example:
lea edx,dwMyLocal ;if dwMyLocal is at [EBP-12], LEA will calculate EDX = EBP-12
Local variables are on the stack, so their location is as an offset from esp (and usually ebp), which means their absolute address/offset isn't known until you're in the function itself - so OFFSET won't work (and ADDR is only a nicety for invoke.)
So it has to be LEA for local variables.
Thank you all, I just couldn't remember.
Dave.
hey,,,,,i've some doubts in regarding LOCAL declaration because we're in situation about LOCAL, that is i often declared byte,word,dword,qword,structs also..data type variables but i didn't get how to declare variables of arrays and strings using the 'LOCAL' i have been through this problem before but i've bypassed it by declaring them globally in .data? or .data sections...and one more thing is it possible that at LOCAL declaration we could assign default values to them.
include \masm32\include\masm32rt.inc
.code
MyTest proc
LOCAL strings[2]
mov strings[0], chr$("string 1")
mov strings[4], chr$("string 2")
mov strings[8], chr$("string 3")
print "The strings", 13, 10
print strings[0], 13, 10
print strings[4], 13, 10
print strings[8], 13, 10
ret
MyTest endp
start: call MyTest
MsgBox 0, "Local strings", "OK?", MB_OK
exit
end start
LOCAL _szBuf[20] :BYTE
allocates 20 bytes for _szBuf
waiting for strings to be declared dev.
Quote from: shaikkareem on December 04, 2014, 11:22:31 PM
waiting for strings to be declared dev.
dev. = devil, deviant, develop? What exactly is "declared"?
Quote from: shaikkareem on December 04, 2014, 11:22:31 PM
waiting for strings to be declared dev.
Strings are just sequences of bytes/characters.
You can use
LOCAL mystring[20]:CHAR if you prefer.
If you mean dynamic length strings, that would require support elsewhere (e.g. a library) and you'd store a pointer to the string instead of the string itself.
thanks Tedd,
your type is similar to what dave given..but i need to declare a assigned one like,
.data
masm db 'masm32',0
with LOCAL directive.
Quote from: shaikkareem on December 06, 2014, 05:19:15 PMi need to declare a assigned one like,
.data
masm db 'masm32',0
with LOCAL directive.
Assembler is not C++, and the syntax you propose is not possible. The closest answer to your request is in reply #5.
LOCAL _szBuf[20] :BYTE
mov dword ptr _szBuf,'msam'
mov dword ptr _szBuf+4,'23'
notice that immediate string data is reversed :P
'23' as a dword will be '32',0,0