News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

how to assign a string to var

Started by Dasar, June 13, 2006, 10:49:37 PM

Previous topic - Next topic

Dasar

hi

i know how to define an initialized string , like:

.data
MyString db "hi, how are you ? ",0



but i want to delcare a var, and then in the code assign some value to it...

for example:

.data?

MyUnKownString db 255 dup(?)  ; string of 255 char

.code
  begin:
    mov MyUnkownString, "hi how are you ?"
    invoke MessageBox, 0, Addr MyUnkownString, addr SomeCaptoin, MB_OK
end begin


i know that i can't mov from memory to memory location, and i have to solutions, using stack(push & pop), or using registers....


and i tested some other things like

mov eax, MyUnknowString

&

mov edi, MyUnkownString

etc...

i tried alot , but can't get it to work   : '(


any help is appreciated ...

mnemonic

If you want to get text into your prog at runtime there are two simple Methods:

  • Allocate a Buffer for the data (text).
Then

  • Let the user type text into a TextBox
  • or
  • Read the text via a console window
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

Mark Jones

Quote from: Dasar on June 13, 2006, 10:49:37 PM
.code
  begin:
    mov MyUnkownString, "hi how are you ?"
    invoke MessageBox, 0, Addr MyUnkownString, addr SomeCaptoin, MB_OK
end begin

Hi Dasar. Mnemonic is on the right track here. Remember that in assembly, all memory is only bytes and pointers. MOV is an elementary instruction, and its only operands types are an immediate value, a memory pointer, or a register. MOV is of course, not smart enough to understand "hi how are you ?" as an operand :bg

If you're writing a Windows GUI application, a commonly used method of getting a string of text is with the GetDlgItemText API. Ex:


    invoke GetDlgItemText,hWnd,1002,addr szSearchQuery,255


This fetches up to 255 bytes from an edit box with the ID of 1002 and stores those bytes at string pointer szSearchQuery. Lookup GetDlgItemText in the Win32.hlp file or at MSDN for more info. :U
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

dsouza123

This uses the szCopy function in masm32.lib, look at masm32.inc for a list of string functions.
Example code for many string functions are in string.asm, one of the examples from MASM32.


  .486                      ; create 32 bit code
  .model flat, stdcall      ; 32 bit memory model
  option casemap :none      ; case sensitive

  include \masm32\include\windows.inc
  include \masm32\include\masm32.inc
  include \masm32\include\gdi32.inc
  include \masm32\include\user32.inc
  include \masm32\include\kernel32.inc

  includelib \masm32\lib\masm32.lib
  includelib \masm32\lib\gdi32.lib
  includelib \masm32\lib\user32.lib
  includelib \masm32\lib\kernel32.lib

.data
  MyString    db "hi, how are you ? ",0
  SomeCaption db "Caption text",0
.data?
  MyUnknownString db 255 dup(?)  ; string of 255 char

.code
begin:
  invoke szCopy,addr MyString,addr MyUnknownString   ; source,destination
  invoke MessageBox, 0, Addr MyUnknownString, addr SomeCaption, MB_OK
  invoke ExitProcess, 0
end begin

Dasar

Thank you all for your replies : )

really, i found a great forum !    : D