News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

LOCAL variables.

Started by KeepingRealBusy, December 03, 2014, 09:43:03 AM

Previous topic - Next topic

KeepingRealBusy

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.

dedndave

LEA calculates the address at runtime   :t

example:
        lea     edx,dwMyLocal      ;if dwMyLocal is at [EBP-12], LEA will calculate EDX = EBP-12

Tedd

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.
Potato2

KeepingRealBusy

Thank you all, I just couldn't remember.

Dave.

shaikkareem

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.

jj2007

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

dedndave

    LOCAL   _szBuf[20] :BYTE

allocates 20 bytes for _szBuf

shaikkareem

waiting for strings to be declared dev.

jj2007

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"?

Tedd

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.
Potato2

shaikkareem

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.

jj2007

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.

dedndave

    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