Dear all

   sometimes, we need a string variable in a procedure,
but this variable was used one time only.
   usually, we use the following way to do that:
----------------------------------------------
         .data (or .const)
szString    db  "MyString", 0
         .code
_ProcName proc
      mov  ebx, offset szString
      ....
_ProcName endp
-----------------------------------------------
   can we define  a local string veriable in a asm procedure immediately? it like:
function xxx()
{
     String a = "abcde";
}
---------

sorry, I come from chinese, my english is very bad. :)

thanks and best regards
billbear
Posted on 2006-10-25 20:13:18 by billbear
I'm not sure if I understand you correctly (I'm a newbie), but I do this:


.386
...
.data
buffer db 128 dup(0)
...
.code
start:
...
myproc proc
  mov eax, "MyString"
  mov dword ptr buffer, eax
  ...
myproc EndP
end start


Hope this helps.
Posted on 2006-10-25 20:29:13 by modchip
Dear modchip

  Yes, your code is my requirement. but:

myproc proc
  mov eax, "MyString"
  mov dword ptr buffer, eax
  ...
myproc EndP


the red sign is a error sentence.

thanks and best regards
billbear
Posted on 2006-10-25 22:41:00 by billbear
The trouble with LOCAL variables is that they are allocated on the stack and need to be initialised first, so your
code would end up something like

  myproc proc
    local mystring[9]:byte
      lea eax,mystring
      mov dword ptr ,'tsym'
      mov dword ptr ,'gnir'
      mov byte ptr ,0
      ...
      ret
  myproc endp

Much more code, when the string is only 9 bytes long...
Posted on 2006-10-25 23:34:03 by sinsi
local buffer:dd
GetProcessHeap
HeapAlloc,eax,0,520
mov ,eax
...
invoke lstrcpy,,somestring
...
GetProcessHeap
HeapFree,eax,0,



push ebx
...
sub esp,128
mov ebx,esp
invoke lstrcpy,ebx,somestring
...
add esp,128
...
pop ebx

Posted on 2006-10-25 23:39:37 by Shoo
billbear: If you want to keep a string close to the proc that uses it, try

_ProcName proc
    .const
        szString db 'MyString',0
    .code
        mov ebx,offset szString
        ...
_ProcName endp

Posted on 2006-10-26 00:16:19 by sinsi
Dear all

Thank you very much!
and I know how to do.

best regards.
billbear
Posted on 2006-10-26 00:38:55 by billbear