.data
MsgString db "Win32 Assembly is Great!",0

The MsgString was initialized.

------------------------
if MsgString don't have default value and then :

1)How to declare var MsgString ?

.data
MsgString db 256 dup(?) ;?? Is it correct ?

2)How to assign "Win32 Assembly is Great!" to var MsgString ?
Posted on 2002-06-26 02:39:11 by fox

1)How to declare var MsgString ?

.data
MsgString db 256 dup(?) ;?? Is it correct ?


Yep pretty much correct.


2)How to assign "Win32 Assembly is Great!" to var MsgString ?


Okay, first you need to put the string "Win32 Assembly is Great!" somewhere. You can define this string in .data also, using another label.

One easy method is to use the szText macro defined as:


szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM


It is used in this manner


szText <label>,<text, etc.>

szText Var1,"Hello everyone!"


Note that szText does not require a terminating null: ',0'

And then do something like this:


.data
MsgString db 256 dup(?) ;?? Is it correct ?

.code
.
.
.
;copy "Win32 Assembly is Great!" to MsgString
szText Win32IsGreatString,"Win32 Assembly is Great!"
Invoke MemCopy, addr Win32IsGreatString,addr MsgString,25
.
.
.

Okay, now for the analysis:
szText creates a variable initialized to "Win32 Assembly is Great!". As it happens, any string constants in assembly must somehow be connected to a label or variable, otherwise it will not be easily accessible.

An alternative could have been:


.data
Win32IsGreatString db "Win32 Assembly is Great!",0



The 'Invoke MemCopy' statement invokes MemCopy, which is part of the MASM32Lib and is included with hutch--'s great MASM32 package. The MemCopy routine copies memory. In this case, it copies FROM Win32IsGreatString TO MsgString ('addr Win32IsGreatString,addr MsgString,' - take note of the 'addr's!!!). The last argument, 25, is the number of bytes to copy. The string "Win32 Assembly is Great!" is by itself 24 bytes (count the characters... ;) ), BUT remember that most of the stuff that Windows expects REQUIRES a terminating zero - which adds one byte, hence 25.

I hope this helped.
Posted on 2002-06-26 03:11:46 by AmkG
Thank you very much.
Posted on 2002-06-26 03:50:23 by fox